| Copyright | (c) Henry J. Wylde, 2015 |
|---|---|
| License | BSD3 |
| Maintainer | public@hjwylde.com |
| Safe Haskell | None |
| Language | Haskell2010 |
Omnifmt.Pipes
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.
- data Status
- = Unknown
- | Error
- | Unsupported
- | NotFound
- | Pretty
- | Ugly
- | Prettified
- omnifmt :: FilePath -> FilePath -> (Status, FilePath, FilePath)
- select :: Monad m => [Status] -> ((Status, FilePath, FilePath) -> m (Status, FilePath, FilePath)) -> Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- checkFileSupported :: MonadReader Config m => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- checkFileExists :: MonadIO m => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- runProgram :: (MonadIO m, MonadLogger m, MonadReader Config m) => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- checkFilePretty :: (MonadIO m, MonadLogger m) => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- commit :: MonadIO m => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m ()
- statusPrinter :: MonadLogger m => Consumer (Status, FilePath, FilePath) m ()
Status
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 |
| 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.
checkFileSupported :: MonadReader Config m => Pipe (Status, FilePath, FilePath) (Status, FilePath, FilePath) m () Source
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
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.