git-fmt-0.3.0.0: Custom git command for formatting code.

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).

NotFound

The file could not be found.

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.

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

Checks all Unknown ugly file paths to see if they exist.

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.

Consumers

statusPrinter :: MonadLogger m => Consumer (Status, FilePath, FilePath) m () Source

Logs the status of each file. Unsupported, NotFound and Pretty are logged using logDebugN. Ugly and Prettified are logged using logInfoN. Unknown and Error are logged using logErrorN.