Options.Applicative.Types

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

Safe Haskell | Safe
Language | Haskell98

Options.Applicative.Types

Synopsis

- data ParseError
  - = ErrorMsg String
  - | InfoMsg String
  - | ShowHelpText
  - | UnknownError
  - | MissingError IsCmdStart SomeParser
- data ParserInfo a = ParserInfo {
  - infoParser :: Parser a
  - infoFullDesc :: Bool
  - infoProgDesc :: Chunk Doc
  - infoHeader :: Chunk Doc
  - infoFooter :: Chunk Doc
  - infoFailureCode :: Int
  - infoIntersperse :: Bool
  }
- data ParserPrefs = ParserPrefs {
  - prefMultiSuffix :: String
  - prefDisambiguate :: Bool
  - prefShowHelpOnError :: Bool
  - prefShowHelpOnEmpty :: Bool
  - prefBacktrack :: Bool
  - prefColumns :: Int
  }
- data Option a = Option {
  - optMain :: OptReader a
  - optProps :: OptProperties
  }
- data OptName
  - = OptShort !Char
  - | OptLong !String
- data OptReader a
  - = OptReader [OptName] (CReader a) ParseError
  - | FlagReader [OptName] !a
  - | ArgReader (CReader a)
  - | CmdReader (Maybe String) [String] (String -> Maybe (ParserInfo a))
- data OptProperties = OptProperties {
  - propVisibility :: OptVisibility
  - propHelp :: Chunk Doc
  - propMetaVar :: String
  - propShowDefault :: Maybe String
  }
- data OptVisibility
  - = Internal
  - | Hidden
  - | Visible
- newtype ReadM a = ReadM {
  - unReadM :: ReaderT String (Except ParseError) a
  }
- readerAsk :: ReadM String
- readerAbort :: ParseError -> ReadM a
- readerError :: String -> ReadM a
- data CReader a = CReader {
  - crCompleter :: Completer
  - crReader :: ReadM a
  }
- data Parser a
  - = NilP (Maybe a)
  - | OptP (Option a)
  - | MultP (Parser (x -> a)) (Parser x)
  - | AltP (Parser a) (Parser a)
  - | BindP (Parser x) (x -> Parser a)
- newtype ParserM r = ParserM {
  - runParserM :: forall x. (r -> Parser x) -> Parser x
  }
- newtype Completer = Completer {
  - runCompleter :: String -> IO [String]
  }
- mkCompleter :: (String -> IO [String]) -> Completer
- newtype CompletionResult = CompletionResult {
  - execCompletion :: String -> IO String
  }
- newtype ParserFailure h = ParserFailure {
  - execFailure :: String -> (h, ExitCode, Int)
  }
- data ParserResult a
  - = Success a
  - | Failure (ParserFailure ParserHelp)
  - | CompletionInvoked CompletionResult
- overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a
- type Args = [String]
- data ArgPolicy
  - = SkipOpts
  - | AllowOpts
- data OptHelpInfo = OptHelpInfo {
  - hinfoMulti :: Bool
  - hinfoDefault :: Bool
  }
- data OptTree a
  - = Leaf a
  - | MultNode [OptTree a]
  - | AltNode [OptTree a]
- data ParserHelp = ParserHelp {
  - helpError :: Chunk Doc
  - helpHeader :: Chunk Doc
  - helpUsage :: Chunk Doc
  - helpBody :: Chunk Doc
  - helpFooter :: Chunk Doc
  }
- data SomeParser = SomeParser (Parser a)
- data Context = Context String (ParserInfo a)
- data IsCmdStart
  - = CmdStart
  - | CmdCont
- fromM :: ParserM a -> Parser a
- oneM :: Parser a -> ParserM a
- manyM :: Parser a -> ParserM [a]
- someM :: Parser a -> ParserM [a]
- optVisibility :: Option a -> OptVisibility
- optMetaVar :: Option a -> String
- optHelp :: Option a -> Chunk Doc
- optShowDefault :: Option a -> Maybe String

# Documentation

data ParseError #

Constructors

ErrorMsg String |
InfoMsg String |
ShowHelpText |
UnknownError |
MissingError IsCmdStart SomeParser |

Instances

Semigroup ParseError # |
Methods (<>) :: ParseError -> ParseError -> ParseError # sconcat :: NonEmpty ParseError -> ParseError # stimes :: Integral b => b -> ParseError -> ParseError #
Monoid ParseError # |
Methods mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError #

data ParserInfo a #

A full description for a runnable `Parser` for a program.

Constructors

ParserInfo |
Fields infoParser :: Parser a the option parser for the program infoFullDesc :: Bool whether the help text should contain full documentation infoProgDesc :: Chunk Doc brief parser description infoHeader :: Chunk Doc header of the full parser description infoFooter :: Chunk Doc footer of the full parser description infoFailureCode :: Int exit code for a parser failure infoIntersperse :: Bool allow regular options and flags to occur after arguments (default: True)

Instances

Functor ParserInfo # |
Methods fmap :: (a -> b) -> ParserInfo a -> ParserInfo b # (<$) :: a -> ParserInfo b -> ParserInfo a #

data ParserPrefs #

Global preferences for a top-level `Parser`.

Constructors

ParserPrefs |
Fields prefMultiSuffix :: String metavar suffix for multiple options prefDisambiguate :: Bool automatically disambiguate abbreviations (default: False) prefShowHelpOnError :: Bool always show help text on parse errors (default: False) prefShowHelpOnEmpty :: Bool show the help text for a command or subcommand if it fails with no input (default: False) prefBacktrack :: Bool backtrack to parent parser when a subcommand fails (default: True) prefColumns :: Int number of columns in the terminal, used to format the help page (default: 80)

Instances

Eq ParserPrefs # |
Methods (==) :: ParserPrefs -> ParserPrefs -> Bool # (/=) :: ParserPrefs -> ParserPrefs -> Bool #
Show ParserPrefs # |
Methods showsPrec :: Int -> ParserPrefs -> ShowS # show :: ParserPrefs -> String # showList :: [ParserPrefs] -> ShowS #

data Option a #

A single option of a parser.

Constructors

Option |
Fields optMain :: OptReader a reader for this option optProps :: OptProperties properties of this option

Instances

Functor Option # |
Methods fmap :: (a -> b) -> Option a -> Option b # (<$) :: a -> Option b -> Option a #
Show (Option a) # |
Methods showsPrec :: Int -> Option a -> ShowS # show :: Option a -> String # showList :: [Option a] -> ShowS #

data OptName #

Constructors

OptShort !Char |
OptLong !String |

Instances

Eq OptName # |
Methods (==) :: OptName -> OptName -> Bool # (/=) :: OptName -> OptName -> Bool #
Ord OptName # |
Methods compare :: OptName -> OptName -> Ordering # (<) :: OptName -> OptName -> Bool # (<=) :: OptName -> OptName -> Bool # (>) :: OptName -> OptName -> Bool # (>=) :: OptName -> OptName -> Bool # max :: OptName -> OptName -> OptName # min :: OptName -> OptName -> OptName #
Show OptName # |
Methods showsPrec :: Int -> OptName -> ShowS # show :: OptName -> String # showList :: [OptName] -> ShowS #

data OptReader a #

An `OptReader` defines whether an option matches an command line argument.

Constructors

OptReader [OptName] (CReader a) ParseError | option reader
FlagReader [OptName] !a | flag reader
ArgReader (CReader a) | argument reader
CmdReader (Maybe String) [String] (String -> Maybe (ParserInfo a)) | command reader

Instances

Functor OptReader # |
Methods fmap :: (a -> b) -> OptReader a -> OptReader b # (<$) :: a -> OptReader b -> OptReader a #

data OptProperties #

Specification for an individual parser option.

Constructors

OptProperties |
Fields propVisibility :: OptVisibility whether this flag is shown is the brief description propHelp :: Chunk Doc help text for this option propMetaVar :: String metavariable for this option propShowDefault :: Maybe String what to show in the help text as the default

Instances

Show OptProperties # |
Methods showsPrec :: Int -> OptProperties -> ShowS # show :: OptProperties -> String # showList :: [OptProperties] -> ShowS #

data OptVisibility #

Visibility of an option in the help text.

Constructors

Internal | does not appear in the help text at all
Hidden | only visible in the full description
Visible | visible both in the full and brief descriptions

Instances

Eq OptVisibility # |
Methods (==) :: OptVisibility -> OptVisibility -> Bool # (/=) :: OptVisibility -> OptVisibility -> Bool #
Ord OptVisibility # |
Methods compare :: OptVisibility -> OptVisibility -> Ordering # (<) :: OptVisibility -> OptVisibility -> Bool # (<=) :: OptVisibility -> OptVisibility -> Bool # (>) :: OptVisibility -> OptVisibility -> Bool # (>=) :: OptVisibility -> OptVisibility -> Bool # max :: OptVisibility -> OptVisibility -> OptVisibility # min :: OptVisibility -> OptVisibility -> OptVisibility #
Show OptVisibility # |
Methods showsPrec :: Int -> OptVisibility -> ShowS # show :: OptVisibility -> String # showList :: [OptVisibility] -> ShowS #

newtype ReadM a #

A newtype over 'ReaderT String Except', used by option readers.

Constructors

ReadM |
Fields unReadM :: ReaderT String (Except ParseError) a

Instances

Monad ReadM # |
Methods (>>=) :: ReadM a -> (a -> ReadM b) -> ReadM b # (>>) :: ReadM a -> ReadM b -> ReadM b # return :: a -> ReadM a # fail :: String -> ReadM a #
Functor ReadM # |
Methods fmap :: (a -> b) -> ReadM a -> ReadM b # (<$) :: a -> ReadM b -> ReadM a #
Applicative ReadM # |
Methods pure :: a -> ReadM a # (<*>) :: ReadM (a -> b) -> ReadM a -> ReadM b # (*>) :: ReadM a -> ReadM b -> ReadM b # (<*) :: ReadM a -> ReadM b -> ReadM a #
Alternative ReadM # |
Methods empty :: ReadM a # (<|>) :: ReadM a -> ReadM a -> ReadM a # some :: ReadM a -> ReadM [a] # many :: ReadM a -> ReadM [a] #
MonadPlus ReadM # |
Methods mzero :: ReadM a # mplus :: ReadM a -> ReadM a -> ReadM a #

readerAsk :: ReadM String #

Return the value being read.

readerAbort :: ParseError -> ReadM a #

Abort option reader by exiting with a `ParseError`.

readerError :: String -> ReadM a #

Abort option reader by exiting with an error message.

data CReader a #

Constructors

CReader |
Fields crCompleter :: Completer crReader :: ReadM a

Instances

Functor CReader # |
Methods fmap :: (a -> b) -> CReader a -> CReader b # (<$) :: a -> CReader b -> CReader a #

data Parser a #

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

Constructors

NilP (Maybe a) |
OptP (Option a) |
MultP (Parser (x -> a)) (Parser x) |
AltP (Parser a) (Parser a) |
BindP (Parser x) (x -> Parser a) |

Instances

Functor Parser # |
Methods fmap :: (a -> b) -> Parser a -> Parser b # (<$) :: a -> Parser b -> Parser a #
Applicative Parser # |
Methods pure :: a -> Parser a # (<*>) :: Parser (a -> b) -> Parser a -> Parser b # (*>) :: Parser a -> Parser b -> Parser b # (<*) :: Parser a -> Parser b -> Parser a #
Alternative Parser # |
Methods empty :: Parser a # (<|>) :: Parser a -> Parser a -> Parser a # some :: Parser a -> Parser [a] # many :: Parser a -> Parser [a] #

newtype ParserM r #

Constructors

ParserM |
Fields runParserM :: forall x. (r -> Parser x) -> Parser x

Instances

Monad ParserM # |
Methods (>>=) :: ParserM a -> (a -> ParserM b) -> ParserM b # (>>) :: ParserM a -> ParserM b -> ParserM b # return :: a -> ParserM a # fail :: String -> ParserM a #
Functor ParserM # |
Methods fmap :: (a -> b) -> ParserM a -> ParserM b # (<$) :: a -> ParserM b -> ParserM a #
Applicative ParserM # |
Methods pure :: a -> ParserM a # (<*>) :: ParserM (a -> b) -> ParserM a -> ParserM b # (*>) :: ParserM a -> ParserM b -> ParserM b # (<*) :: ParserM a -> ParserM b -> ParserM a #

newtype Completer #

Constructors

Completer |
Fields runCompleter :: String -> IO [String]

Instances

Monoid Completer # |
Methods mempty :: Completer # mappend :: Completer -> Completer -> Completer # mconcat :: [Completer] -> Completer #

mkCompleter :: (String -> IO [String]) -> Completer #

newtype CompletionResult #

Constructors

CompletionResult |
Fields execCompletion :: String -> IO String

Instances

Show CompletionResult # |
Methods showsPrec :: Int -> CompletionResult -> ShowS # show :: CompletionResult -> String # showList :: [CompletionResult] -> ShowS #

newtype ParserFailure h #

Constructors

ParserFailure |
Fields execFailure :: String -> (h, ExitCode, Int)

Instances

Functor ParserFailure # |
Methods fmap :: (a -> b) -> ParserFailure a -> ParserFailure b # (<$) :: a -> ParserFailure b -> ParserFailure a #
Show h => Show (ParserFailure h) # |
Methods showsPrec :: Int -> ParserFailure h -> ShowS # show :: ParserFailure h -> String # showList :: [ParserFailure h] -> ShowS #

data ParserResult a #

Result of `execParserPure`.

Constructors

Success a |
Failure (ParserFailure ParserHelp) |
CompletionInvoked CompletionResult |

Instances

Monad ParserResult # |
Methods (>>=) :: ParserResult a -> (a -> ParserResult b) -> ParserResult b # (>>) :: ParserResult a -> ParserResult b -> ParserResult b # return :: a -> ParserResult a # fail :: String -> ParserResult a #
Functor ParserResult # |
Methods fmap :: (a -> b) -> ParserResult a -> ParserResult b # (<$) :: a -> ParserResult b -> ParserResult a #
Applicative ParserResult # |
Methods pure :: a -> ParserResult a # (<*>) :: ParserResult (a -> b) -> ParserResult a -> ParserResult b # (*>) :: ParserResult a -> ParserResult b -> ParserResult b # (<*) :: ParserResult a -> ParserResult b -> ParserResult a #
Show a => Show (ParserResult a) # |
Methods showsPrec :: Int -> ParserResult a -> ShowS # show :: ParserResult a -> String # showList :: [ParserResult a] -> ShowS #

overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a #

type Args = [String] #

data ArgPolicy #

Policy for how to handle options within the parse

Constructors

SkipOpts | Inputs beginning with `-` or `--` are treated as options or flags, and can be mixed with arguments.
AllowOpts | All input is treated as positional arguments. Used after a bare `--` input, and also with `noIntersperse` policy.

Instances

Eq ArgPolicy # |
Methods (==) :: ArgPolicy -> ArgPolicy -> Bool # (/=) :: ArgPolicy -> ArgPolicy -> Bool #
Show ArgPolicy # |
Methods showsPrec :: Int -> ArgPolicy -> ShowS # show :: ArgPolicy -> String # showList :: [ArgPolicy] -> ShowS #

data OptHelpInfo #

Constructors

OptHelpInfo |
Fields hinfoMulti :: Bool hinfoDefault :: Bool

Instances

Eq OptHelpInfo # |
Methods (==) :: OptHelpInfo -> OptHelpInfo -> Bool # (/=) :: OptHelpInfo -> OptHelpInfo -> Bool #
Show OptHelpInfo # |
Methods showsPrec :: Int -> OptHelpInfo -> ShowS # show :: OptHelpInfo -> String # showList :: [OptHelpInfo] -> ShowS #

data OptTree a #

Constructors

Leaf a |
MultNode [OptTree a] |
AltNode [OptTree a] |

Instances

Show a => Show (OptTree a) # |
Methods showsPrec :: Int -> OptTree a -> ShowS # show :: OptTree a -> String # showList :: [OptTree a] -> ShowS #

data ParserHelp #

Constructors

ParserHelp |
Fields helpError :: Chunk Doc helpHeader :: Chunk Doc helpUsage :: Chunk Doc helpBody :: Chunk Doc helpFooter :: Chunk Doc

Instances

Show ParserHelp # |
Methods showsPrec :: Int -> ParserHelp -> ShowS # show :: ParserHelp -> String # showList :: [ParserHelp] -> ShowS #
Semigroup ParserHelp # |
Methods (<>) :: ParserHelp -> ParserHelp -> ParserHelp # sconcat :: NonEmpty ParserHelp -> ParserHelp # stimes :: Integral b => b -> ParserHelp -> ParserHelp #
Monoid ParserHelp # |
Methods mempty :: ParserHelp # mappend :: ParserHelp -> ParserHelp -> ParserHelp # mconcat :: [ParserHelp] -> ParserHelp #

data SomeParser #

Constructors

SomeParser (Parser a) |

data Context #

Subparser context, containing the `name` of the subparser, and its parser info. Used by parserFailure to display relevant usage information when parsing inside a subparser fails.

Constructors

Context String (ParserInfo a) |

data IsCmdStart #

Constructors

CmdStart |
CmdCont |

Instances

Show IsCmdStart # |
Methods showsPrec :: Int -> IsCmdStart -> ShowS # show :: IsCmdStart -> String # showList :: [IsCmdStart] -> ShowS #

fromM :: ParserM a -> Parser a #

oneM :: Parser a -> ParserM a #

manyM :: Parser a -> ParserM [a] #

someM :: Parser a -> ParserM [a] #

optVisibility :: Option a -> OptVisibility #

optMetaVar :: Option a -> String #

optHelp :: Option a -> Chunk Doc #

optShowDefault :: Option a -> Maybe String #