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

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

Omnifmt.Config

Contents

Description

Configuration data structures.

Synopsis

Config

data Config Source

A collection of Programs.

Constructors

Config 

Fields

programs :: [Program]
 

emptyConfig :: Config Source

An empty config (no 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.

TODO (hjw): fix the bug where it won't search the root directory.

defaultFileName :: FilePath Source

The file name of the default config, '.omnifmt.yaml'.

programFor :: Config -> Text -> Maybe Program Source

Attempts to find a Program for the given extension. Programs are searched in order as provided by the Config and the first match will be returned.

unsafeProgramFor :: Config -> Text -> Program Source

fromJust . programFor

supported :: Config -> Text -> Bool Source

Checks if the given extension is supported (i.e., there is a Program for it).

Program

data Program Source

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.

Constructors

Program 

Fields

name :: Text

A semantic name (has no impact on formatting).

extensions :: [Text]

A list of extensions, without a period prefix.

command :: Text

A command to run in a shell that prettifies an input file and writes to an output file.

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}}'.