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

Safe HaskellSafe-Infered

Options.Applicative.Builder

Contents

Synopsis

Parser builders

This module contains utility functions and combinators to create parsers for individual options.

Each parser builder takes an option modifier. A modifier can be created by composing the basic modifiers provided by this module using the Monoid operations mempty and mappend, or their aliases idm and &.

For example:

 out = strOption
     ( long "output"
     & short 'o'
     & metavar "FILENAME" )

creates a parser for an option called "output".

subparser :: Mod CommandFields a -> Parser aSource

Builder for a command parser. The command modifier can be used to specify individual commands.

argument :: (String -> Maybe a) -> Mod ArgumentFields a -> Parser aSource

Builder for an argument parser.

arguments :: (String -> Maybe a) -> Mod ArgumentFields [a] -> Parser [a]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 -.

flagSource

Arguments

:: a

default value

-> a

active value

-> Mod FlagFields a

option modifier

-> Parser a 

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.

flag'Source

Arguments

:: a

active value

-> Mod FlagFields a

option modifier

-> Parser a 

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 -> Parser BoolSource

Builder for a boolean flag.

 switch = flag False True

nullOption :: Mod OptionFields a -> Parser aSource

Builder for an option with a null reader. A non-trivial reader can be added using the reader modifier.

strOption :: Mod OptionFields String -> Parser StringSource

Builder for an option taking a String argument.

option :: Read a => Mod OptionFields a -> Parser aSource

Builder for an option using the auto reader.

Modifiers

short :: HasName f => Char -> Mod f aSource

Specify a short name for an option.

long :: HasName f => String -> Mod f aSource

Specify a long name for an option.

help :: String -> Mod f aSource

Specify the help text for an option.

value :: a -> Mod f aSource

metavar :: String -> Mod f aSource

Specify the metavariable.

reader :: (String -> Maybe a) -> Mod OptionFields aSource

Specify the Option reader.

hidden :: Mod f aSource

Hide this option from the brief description.

internal :: Mod f aSource

Hide this option from the help text

command :: String -> ParserInfo a -> Mod CommandFields aSource

Add a command to a subparser option.

idm :: Monoid m => mSource

(&) :: Monoid m => m -> m -> mSource

Readers

A collection of basic Option readers.

auto :: Read a => String -> Maybe aSource

Option reader based on the Read type class.

str :: String -> Maybe StringSource

String Option reader.

disabled :: String -> Maybe aSource

Null Option reader. All arguments will fail validation.

Internals

data Mod f a Source

Instances

Monoid (Mod f a) 

Builder for ParserInfo

data InfoMod a Source

Modifier for ParserInfo.

Instances

fullDesc :: InfoMod aSource

Specify a full description for this parser.

header :: String -> InfoMod aSource

Specify a header for this parser.

progDesc :: String -> InfoMod aSource

Specify a short program description.

footer :: String -> InfoMod aSource

Specify a footer for this parser.

failureCode :: Int -> InfoMod aSource

Specify an exit code if a parse error occurs.

info :: Parser a -> InfoMod a -> ParserInfo aSource

Create a ParserInfo given a Parser and a modifier.

Builder for ParserPrefs