Safe Haskell | Safe-Infered |
---|
- subparser :: Mod CommandFields a b -> Parser b
- argument :: (String -> Maybe a) -> Mod Identity a b -> Parser b
- arguments :: (String -> Maybe a) -> Mod Identity a b -> Parser [b]
- flag :: a -> a -> Mod FlagFields a b -> Parser b
- flag' :: a -> Mod FlagFields a b -> Parser b
- switch :: Mod FlagFields Bool a -> Parser a
- nullOption :: Mod OptionFields a b -> Parser b
- strOption :: Mod OptionFields String a -> Parser a
- option :: Read a => Mod OptionFields a b -> Parser b
- short :: HasName f => Char -> Mod f a a
- long :: HasName f => String -> Mod f a a
- help :: String -> Mod f a a
- value :: a -> Mod f a a
- metavar :: String -> Mod f a a
- reader :: (String -> Maybe a) -> Mod OptionFields a a
- hidden :: Mod f a a
- internal :: Mod f a a
- transform :: Functor f => (a -> b) -> Mod f a b
- command :: String -> ParserInfo a -> Mod CommandFields a a
- idm :: Category hom => hom a a
- (&) :: Category hom => hom a b -> hom b c -> hom a c
- auto :: Read a => String -> Maybe a
- str :: String -> Maybe String
- disabled :: String -> Maybe a
- data Mod f a b
- class HasName f
- data OptionFields a
- data FlagFields a
- data CommandFields a
- data InfoMod a b
- fullDesc :: InfoMod a a
- header :: String -> InfoMod a a
- progDesc :: String -> InfoMod a a
- footer :: String -> InfoMod a a
- failureCode :: Int -> InfoMod a a
- info :: Parser a -> InfoMod a a -> ParserInfo a
- type PrefsMod = PrefsModC ParserPrefs ParserPrefs
- multiSuffix :: String -> PrefsMod
- prefs :: PrefsMod -> ParserPrefs
Parser builders
This module contains utility functions and combinators to create parsers for individual options.
Each parser builder takes an option modifier, which can be specified by
composing basic modifiers using &
and idm
(which are just convenient
synonyms for the Category
operations >>>
and
id
).
For example:
out = strOption ( long "output" & short 'o' & metavar "FILENAME" )
creates a parser for an option called "output".
subparser :: Mod CommandFields a b -> Parser bSource
Builder for a command parser. The command
modifier can be used to
specify individual commands.
argument :: (String -> Maybe a) -> Mod Identity a b -> Parser bSource
Builder for an argument parser.
arguments :: (String -> Maybe a) -> Mod Identity a b -> Parser [b]Source
Builder for an argument list parser. All arguments are collected and returned as a list.
Note that arguments starting with
are ignored.
-
This parser accepts a special argument: --
. When a --
is found on the
command line, all following arguments are included in the result, even if
they start with
.
-
:: a | default value |
-> a | active value |
-> Mod FlagFields a b | option modifier |
-> Parser b |
Builder for a flag parser.
A flag that switches from a "default value" to an "active value" when
encountered. For a simple boolean value, use switch
instead.
:: a | active value |
-> Mod FlagFields a b | option modifier |
-> Parser b |
Builder for a flag parser without a default value.
Same as flag
, but with no default value. In particular, this flag will
never parse successfully by itself.
It still makes sense to use it as part of a composite parser. For example
length <$> many (flag' () (short 't'))
is a parser that counts the number of -t arguments on the command line.
switch :: Mod FlagFields Bool a -> Parser aSource
Builder for a boolean flag.
switch = flag False True
nullOption :: Mod OptionFields a b -> Parser bSource
Builder for an option with a null reader. A non-trivial reader can be
added using the reader
modifier.
strOption :: Mod OptionFields String a -> Parser aSource
Builder for an option taking a String
argument.
option :: Read a => Mod OptionFields a b -> Parser bSource
Builder for an option using the auto
reader.
Modifiers
transform :: Functor f => (a -> b) -> Mod f a bSource
Apply a transformation to the return value of this option.
This can be used, for example, to provide a default value for a required option, like:
strOption ( transform Just & value Nothing )
command :: String -> ParserInfo a -> Mod CommandFields a aSource
Add a command to a subparser option.
Readers
A collection of basic Option
readers.
Internals
Builder for ParserInfo
failureCode :: Int -> InfoMod a aSource
Specify an exit code if a parse error occurs.
info :: Parser a -> InfoMod a a -> ParserInfo aSource
Create a ParserInfo
given a Parser
and a modifier.
Builder for ParserPrefs
type PrefsMod = PrefsModC ParserPrefs ParserPrefsSource
Modifier for ParserPrefs
.
multiSuffix :: String -> PrefsModSource
prefs :: PrefsMod -> ParserPrefsSource