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

Safe HaskellSafe
LanguageHaskell98

Options.Applicative.Extra

Contents

Synopsis

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.

execParserMaybe :: ParserInfo a -> [String] -> Maybe a Source #

Deprecated: Use execParserPure together with getParseResult instead

Run a program description in pure code.

This function behaves like execParser, but can be called from pure code. Note that, in case of errors, no message is displayed, and this function simply returns Nothing.

If you need to keep track of error messages, use execParserPure instead.

customExecParser :: ParserPrefs -> ParserInfo a -> IO a Source #

Run a program description with custom preferences.

customExecParserMaybe :: ParserPrefs -> ParserInfo a -> [String] -> Maybe a Source #

Deprecated: Use execParserPure together with getParseResult instead

Run a program description with custom preferences in pure code.

See execParserMaybe for details.

execParserPure Source #

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.

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

newtype ParserFailure h Source #

Constructors

ParserFailure 

Fields

data ParserPrefs Source #

Global preferences for a top-level Parser.

Constructors

ParserPrefs 

Fields