omnifmt-0.2.1.1: A pretty-printer wrapper to faciliate ease of formatting during development.

Copyright(c) Henry J. Wylde, 2015
LicenseBSD3
Maintainerpublic@hjwylde.com
Safe HaskellNone
LanguageHaskell2010

Omnifmt.Pipes

Contents

Description

Pipeline for formatting files. The functions listed here are in order of the recommended chain, but it is possible to mix and match them or add custom functions inbetween.

Synopsis

Status

data Status Source

A status for a file going through the omnifmt pipeline.

Constructors

Unknown

The file has not been processed.

Error

An error occurred somewhere.

Unsupported

The file type is unsupported (i.e., no applicable Program).

Timeout

A command timed out.

Pretty

The file is pretty.

Ugly

The file is ugly.

Prettified

The file is now pretty.

Producers

omnifmt :: FilePath -> FilePath -> (Status, FilePath, FilePath) Source

Takes an input (ugly) file path and an empty output file path and prepends the Unknown status to them.

Transformers

select :: Monad m => [Status] -> ((Status, FilePath, FilePath) -> m (Status, FilePath, FilePath)) -> Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Utility method for applying a function to files that match certain statuses. Any files that don't match the given statuses will be passed through unmodified.

runProgram :: (MonadIO m, MonadLogger m, MonadReader Config m) => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Runs the applicable Program's command on all Unknown files. This reads in the ugly file path and writes out to the pretty file path.

Note that this function assumes that the file is supported, so make sure the file has been piped through checkFileSupported first.

Any errors that occur are logged using logDebugN.

checkFilePretty :: (MonadIO m, MonadLogger m) => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Runs a diff over the two file paths for all Unknown files.

This function always updates the status to either Ugly, Pretty or Error.

Any errors that occur are logged using logDebugN.

commit :: MonadIO m => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Commits the result of runProgram. I.e., writes over all Ugly files with their corresponding pretty file.

This function updates the status to Prettified.

diff :: (MonadIO m, MonadLogger m) => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Prints out the diff of all ugly files to standard output.

printFileStatus :: MonadLogger m => (Status -> Text -> m ()) -> Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source

Logs the status of each file using the given function.