Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- type OptParser a = Ap Option a
- parseConfig :: FilePath -> Text -> OptParser a -> Either CustomParseError a
- parseConfigFile :: FilePath -> OptParser a -> IO (Either CustomParseError a)
- option :: OptionArgument a => Text -> a -> Text -> OptParser a
- customOption :: Text -> a -> Text -> Text -> Text -> OParser a -> OptParser a
- parserDefault :: OptParser a -> a
- parserExample :: OptParser a -> Text
- data ConfParseError
- type OParser = Parsec ConfParseError Text
- data Option a
- class OptionArgument a
Documentation
type OptParser a = Ap Option a Source #
The main parser type. Use option
and the Applicative
instance to create those.
:: 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
.
Parse a config file from an actual file in the filesystem.
:: OptionArgument a | |
=> Text | The option name |
-> a | The default value |
-> Text | A help string for the option. Will be used by |
-> OptParser a |
OptParser
that parses one option.
Can be combined with the Applicative
instance for OptParser
. See the
module documentation for an example.
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 ConfParseError Source #
Errors that can occur during parsing. Use the Show
instance for printing.
Instances
Eq ConfParseError Source # | |
Defined in ConfigParser (==) :: ConfParseError -> ConfParseError -> Bool # (/=) :: ConfParseError -> ConfParseError -> Bool # | |
Ord ConfParseError Source # | |
Defined in ConfigParser compare :: ConfParseError -> ConfParseError -> Ordering # (<) :: ConfParseError -> ConfParseError -> Bool # (<=) :: ConfParseError -> ConfParseError -> Bool # (>) :: ConfParseError -> ConfParseError -> Bool # (>=) :: ConfParseError -> ConfParseError -> Bool # max :: ConfParseError -> ConfParseError -> ConfParseError # min :: ConfParseError -> ConfParseError -> ConfParseError # | |
Show ConfParseError Source # | |
Defined in ConfigParser showsPrec :: Int -> ConfParseError -> ShowS # show :: ConfParseError -> String # showList :: [ConfParseError] -> ShowS # | |
ShowErrorComponent ConfParseError Source # | |
Defined in ConfigParser |
An option in the config file. Use option
as a smart constructor.
class OptionArgument a Source #
Class for supported option types.
At the moment, orphan instances are not supported
mkParser, printArgument
Instances
OptionArgument Int Source # | |
Defined in ConfigParser | |
OptionArgument Integer Source # | |
Defined in ConfigParser | |
OptionArgument String Source # | |
Defined in ConfigParser | |
OptionArgument Text Source # | |
Defined in ConfigParser |