optparse-applicative-0.1.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, 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 a b -> Parser bSource

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

argument :: (String -> Maybe a) -> Mod f a a b -> Parser bSource

Builder for an argument parser.

arguments :: (String -> Maybe a) -> Mod f a [a] b -> Parser bSource

Builder for an argument list parser. All arguments are collected and returned as a list.

flagSource

Arguments

:: a

default value

-> a

active value

-> Mod FlagFields a 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.

switch :: Mod FlagFields Bool Bool a -> Parser aSource

Builder for a boolean flag.

 switch = flag False True

nullOption :: Mod OptionFields a 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 String a -> Parser aSource

Builder for an option taking a String argument.

option :: Read a => Mod OptionFields a a b -> Parser bSource

Builder for an option using the auto reader.

Modifiers

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

Specify a short name for an option.

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

Specify a long name for an option.

help :: String -> Mod f r a aSource

Specify the help text for an option.

value :: a -> Mod f r a aSource

Specify a default value for an option.

metavar :: String -> Mod f r a aSource

Specify the metavariable.

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

Specify the option reader.

hide :: Mod f r a aSource

Hide this option.

multi :: Mod f r a [a]Source

Create a multi-valued option.

transform :: (a -> b) -> Mod f r 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 r -> Mod CommandFields r a aSource

Add a command to a subparser option.

idm :: Category hom => hom a aSource

Trivial option modifier.

(&) :: Category hom => hom a b -> hom b c -> hom a cSource

Compose modifiers.

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 r a b Source

Instances

Category (Mod f r) 

Builder for ParserInfo

data InfoMod a b Source

Modifier for ParserInfo.

Instances

fullDesc :: InfoMod a aSource

Specify a full description for this parser.

header :: String -> InfoMod a aSource

Specify a header for this parser.

progDesc :: String -> InfoMod a aSource

Specify a short program description.

footer :: String -> InfoMod a aSource

Specify a footer for this parser.

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.