optparse-applicative-0.15.1.0: Utilities and combinators for parsing command line options

Options.Applicative.Common

Synopsis

Option parsers

A Parser is composed of a list of options. Several kinds of options are supported:

• Flags: simple no-argument options. When a flag is encountered on the command line, its value is returned.
• Options: options with an argument. An option can define a reader, which converts its argument from String to the desired value, or throws a parse error if the argument does not validate correctly.
• Arguments: positional arguments, validated in the same way as option arguments.
• Commands. A command defines a completely independent sub-parser. When a command is encountered, the whole command line is passed to the corresponding parser.

data Parser a Source #

A Parser a is an option parser returning a value of type a.

Instances
 Source # Instance detailsDefined in Options.Applicative.Types Methodsfmap :: (a -> b) -> Parser a -> Parser b #(<$) :: a -> Parser b -> Parser a # Source # Instance detailsDefined in Options.Applicative.Types Methodspure :: a -> Parser a #(<*>) :: Parser (a -> b) -> Parser a -> Parser b #liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c #(*>) :: Parser a -> Parser b -> Parser b #(<*) :: Parser a -> Parser b -> Parser a # Source # Instance detailsDefined in Options.Applicative.Types Methodsempty :: Parser a #(<|>) :: Parser a -> Parser a -> Parser a #some :: Parser a -> Parser [a] #many :: Parser a -> Parser [a] # liftOpt :: Option a -> Parser a Source # Create a parser composed of a single option. Program descriptions data ParserInfo a Source # A full description for a runnable Parser for a program. Constructors  ParserInfo FieldsinfoParser :: Parser athe option parser for the programinfoFullDesc :: Boolwhether the help text should contain full documentationinfoProgDesc :: Chunk Docbrief parser descriptioninfoHeader :: Chunk Docheader of the full parser descriptioninfoFooter :: Chunk Docfooter of the full parser descriptioninfoFailureCode :: Intexit code for a parser failureinfoPolicy :: ArgPolicyallow regular options and flags to occur after arguments (default: InterspersePolicy) Instances  Source # Instance detailsDefined in Options.Applicative.Types Methodsfmap :: (a -> b) -> ParserInfo a -> ParserInfo b #(<$) :: a -> ParserInfo b -> ParserInfo a #

Global preferences for a top-level Parser.

Constructors

 ParserPrefs FieldsprefMultiSuffix :: Stringmetavar suffix for multiple optionsprefDisambiguate :: Boolautomatically disambiguate abbreviations (default: False)prefShowHelpOnError :: Boolalways show help text on parse errors (default: False)prefShowHelpOnEmpty :: Boolshow the help text for a command or subcommand if it fails with no input (default: False)prefBacktrack :: Backtrackingbacktrack to parent parser when a subcommand fails (default: Backtrack)prefColumns :: Intnumber of columns in the terminal, used to format the help page (default: 80)prefHelpLongEquals :: Boolwhen displaying long names in usage and help, use an '=' sign for long names, rather than a single space (default: False)
Instances
 Source # Instance detailsDefined in Options.Applicative.Types Methods Source # Instance detailsDefined in Options.Applicative.Types MethodsshowList :: [ParserPrefs] -> ShowS #

Running parsers

runParser :: MonadP m => ArgPolicy -> IsCmdStart -> Parser a -> Args -> m (a, Args) Source #

Apply a Parser to a command line, and return a result and leftover arguments. This function returns an error if any parsing error occurs, or if any options are missing and don't have a default value.

evalParser :: Parser a -> Maybe a Source #

The default value of a Parser. This function returns an error if any of the options don't have a default value.

Low-level utilities

mapParser :: (forall x. OptHelpInfo -> Option x -> b) -> Parser a -> [b] Source #

Map a polymorphic function over all the options of a parser, and collect the results in a list.

treeMapParser :: (forall x. OptHelpInfo -> Option x -> b) -> Parser a -> OptTree b Source #

Like mapParser, but collect the results in a tree structure.