Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Options.Applicative.Extra
Contents
Synopsis
- helper :: Parser (a -> a)
- hsubparser :: Mod CommandFields a -> Parser a
- execParser :: ParserInfo a -> IO a
- customExecParser :: ParserPrefs -> ParserInfo a -> IO a
- execParserPure :: ParserPrefs -> ParserInfo a -> [String] -> ParserResult a
- getParseResult :: ParserResult a -> Maybe a
- handleParseResult :: ParserResult a -> IO a
- parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp
- renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode)
- newtype ParserFailure h = ParserFailure {
- execFailure :: String -> (h, ExitCode, Int)
- overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a
- data ParserResult a
- data ParserPrefs = ParserPrefs {}
- newtype CompletionResult = CompletionResult {
- execCompletion :: String -> IO String
Extra parser utilities
This module contains high-level functions to run parsers.
helper :: Parser (a -> a) Source #
A hidden "helper" option which always fails.
A common usage pattern is to apply this applicatively when
creating a ParserInfo
opts :: ParserInfo Sample opts = info (sample <**> helper) mempty
hsubparser :: Mod CommandFields a -> Parser a Source #
Builder for a command parser with a "helper" option attached.
Used in the same way as subparser
, but includes a "--help|-h" inside
the subcommand.
execParser :: ParserInfo a -> IO a Source #
Run a program description.
Parse command line arguments. Display help text and exit if any parse error occurs.
customExecParser :: ParserPrefs -> ParserInfo a -> IO a Source #
Run a program description with custom preferences.
Arguments
:: ParserPrefs | Global preferences for this parser |
-> ParserInfo a | Description of the program to run |
-> [String] | Program arguments |
-> ParserResult a |
The most general way to run a program description in pure code.
getParseResult :: ParserResult a -> Maybe a Source #
Extract the actual result from a ParserResult
value.
This function returns Nothing
in case of errors. Possible error messages
or completion actions are simply discarded.
If you want to display error messages and invoke completion actions
appropriately, use handleParseResult
instead.
handleParseResult :: ParserResult a -> IO a Source #
Handle ParserResult
.
parserFailure :: ParserPrefs -> ParserInfo a -> ParseError -> [Context] -> ParserFailure ParserHelp Source #
Generate a ParserFailure
from a ParseError
in a given Context
.
This function can be used, for example, to show the help text for a parser:
handleParseResult . Failure $ parserFailure pprefs pinfo ShowHelpText mempty
renderFailure :: ParserFailure ParserHelp -> String -> (String, ExitCode) Source #
newtype ParserFailure h Source #
Constructors
ParserFailure | |
Fields
|
Instances
Functor ParserFailure Source # | |
Defined in Options.Applicative.Types Methods fmap :: (a -> b) -> ParserFailure a -> ParserFailure b # (<$) :: a -> ParserFailure b -> ParserFailure a # | |
Show h => Show (ParserFailure h) Source # | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> ParserFailure h -> ShowS # show :: ParserFailure h -> String # showList :: [ParserFailure h] -> ShowS # |
overFailure :: (ParserHelp -> ParserHelp) -> ParserResult a -> ParserResult a Source #
data ParserResult a Source #
Result of execParserPure
.
Constructors
Success a | |
Failure (ParserFailure ParserHelp) | |
CompletionInvoked CompletionResult |
Instances
data ParserPrefs Source #
Global preferences for a top-level Parser
.
Constructors
ParserPrefs | |
Fields
|
Instances
Eq ParserPrefs Source # | |
Defined in Options.Applicative.Types | |
Show ParserPrefs Source # | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> ParserPrefs -> ShowS # show :: ParserPrefs -> String # showList :: [ParserPrefs] -> ShowS # |
newtype CompletionResult Source #
Constructors
CompletionResult | |
Fields
|
Instances
Show CompletionResult Source # | |
Defined in Options.Applicative.Types Methods showsPrec :: Int -> CompletionResult -> ShowS # show :: CompletionResult -> String # showList :: [CompletionResult] -> ShowS # |