Copyright | (c) Henry J. Wylde 2015 |
---|---|
License | BSD3 |
Maintainer | public@hjwylde.com |
Safe Haskell | None |
Language | Haskell2010 |
Configuration data structures.
- data Config = Config {}
- emptyConfig :: Config
- readConfig :: (MonadIO m, MonadLogger m) => FilePath -> m (Maybe Config)
- nearestConfigFile :: MonadIO m => FilePath -> m (Maybe FilePath)
- defaultFileName :: FilePath
- programFor :: Config -> Text -> Maybe Program
- unsafeProgramFor :: Config -> Text -> Program
- supported :: Config -> Text -> Bool
- data Program = Program {}
- emptyProgram :: Program
- substitute :: Text -> [(Text, Text)] -> Text
- usesInputVariable :: Text -> Bool
- usesOutputVariable :: Text -> Bool
- inputVariableName :: Text
- outputVariableName :: Text
Config
A collection of Program
s.
Optionally may include a source attribute of the file the config was created from.
emptyConfig :: Config Source #
An empty config (no source or programs).
readConfig :: (MonadIO m, MonadLogger m) => FilePath -> m (Maybe Config) Source #
Reads a config from the given file path if possible.
If an error occurs it is logged using logDebugN
.
nearestConfigFile :: MonadIO m => FilePath -> m (Maybe FilePath) Source #
Finds the nearest config file by searching from the given directory upwards.
defaultFileName :: FilePath Source #
The file name of the default config, '.omnifmt.yaml'.
supported :: Config -> Text -> Bool Source #
Checks if the given extension is supported (i.e., there is a Program
for it).
Program
A program has a semantic name, associated extensions and formatting command. The command string may contain variables, denoted by strings surrounded with '{{..}}'. The command should return a 0 exit code for success, or a non-0 exit code for failure.
emptyProgram :: Program Source #
The empty program (no extensions and the command always fails).
substitute :: Text -> [(Text, Text)] -> Text Source #
Substitutes the mapping throughout the command.
The mapping is a tuple of (variable, value)
.
Values given are quoted and have any backslashes and double quotaiton marks escaped.
usesInputVariable :: Text -> Bool Source #
Checks whether the text uses the input variable (inputVariableName
).
usesOutputVariable :: Text -> Bool Source #
Checks whether the text uses the output variable (outputVariableName
).
inputVariableName :: Text Source #
The input variable name, '{{input}}'.
outputVariableName :: Text Source #
The output variable name, '{{output}}'.