hledger-iadd-1.3.10: A terminal UI as drop-in replacement for hledger add

Safe HaskellNone
LanguageHaskell2010

ConfigParser

Description

Applicative config parser.

This parses config files in the style of optparse-applicative. It supports automatic generation of a default config both as datatype and in printed form.

Example:

data Config = Config
  { test :: Text
  , foobar :: Int
  }

confParser :: ConfParser Config
confParser = Config
         <$> option "test" "default value" "Help for test"
         <*> option "foobar" 42 "Help for foobar"

This parses a config file like the following:

# This is a comment
test = "something"
foobar = 23
Synopsis

Documentation

type OptParser a = Ap Option a Source #

The main parser type. Use option and the Applicative instance to create those.

parseConfig Source #

Arguments

:: FilePath

File path to use in error messages

-> Text

The input test

-> OptParser a

The parser to use

-> Either CustomParseError a 

Parse a config file from a Text.

parseConfigFile Source #

Arguments

:: FilePath

Path to the file

-> OptParser a

The parser to use

-> IO (Either CustomParseError a) 

Parse a config file from an actual file in the filesystem.

option Source #

Arguments

:: OptionArgument a 
=> Text

The option name

-> a

The default value

-> Text

A help string for the option. Will be used by parserExample to create helpful comments.

-> OptParser a 

OptParser that parses one option.

Can be combined with the Applicative instance for OptParser. See the module documentation for an example.

customOption Source #

Arguments

:: Text

The option name

-> a

The default Value

-> Text

A textual representation of the default value

-> Text

A help string for the option

-> Text

A description of the expected type such sas "string" or "integer"

-> OParser a

Parser for the option

-> OptParser a 

parserDefault :: OptParser a -> a Source #

Returns the default value of a given parser.

This default value is computed from the default arguments of the option constructor. For the parser from the module description, the default value would be:

Config { test = "default value"
       , foobar :: 42
       }

parserExample :: OptParser a -> Text Source #

Generate the default config file.

This returns a valid config file, filled with the default values of every option and using the help string of these options as comments.

data Option a Source #

An option in the config file. Use option as a smart constructor.

Instances
Functor Option Source # 
Instance details

Defined in ConfigParser

Methods

fmap :: (a -> b) -> Option a -> Option b #

(<$) :: a -> Option b -> Option a #

class OptionArgument a Source #

Class for supported option types.

At the moment, orphan instances are not supported

Minimal complete definition

mkParser, printArgument

Instances
OptionArgument Int Source # 
Instance details

Defined in ConfigParser

OptionArgument Integer Source # 
Instance details

Defined in ConfigParser

OptionArgument String Source # 
Instance details

Defined in ConfigParser

OptionArgument Text Source # 
Instance details

Defined in ConfigParser