|
Packit |
3fa651 |
module Options.Applicative (
|
|
Packit |
3fa651 |
-- * Applicative option parsers
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | This module exports all one should need for defining and using
|
|
Packit |
3fa651 |
-- optparse-applicative command line option parsers.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- See <https://github.com/pcapriotti/optparse-applicative> for a tutorial,
|
|
Packit |
3fa651 |
-- and a general introduction to applicative option parsers.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- See the sections below for more detail
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Exported modules
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | The standard @Applicative@ module is re-exported here for convenience.
|
|
Packit |
3fa651 |
module Control.Applicative,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Option Parsers
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | A 'Parser' is the core type in optparse-applicative. A value of type
|
|
Packit |
3fa651 |
-- @Parser a@ represents a specification for a set of options, which will
|
|
Packit |
3fa651 |
-- yield a value of type a when the command line arguments are successfully
|
|
Packit |
3fa651 |
-- parsed.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- There are several types of primitive 'Parser'.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- * Flags: simple no-argument options. When a flag is encountered on the
|
|
Packit |
3fa651 |
-- command line, its value is returned.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- * Options: options with an argument. An option can define a /reader/,
|
|
Packit |
3fa651 |
-- which converts its argument from String to the desired value, or throws a
|
|
Packit |
3fa651 |
-- parse error if the argument does not validate correctly.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- * Arguments: positional arguments, validated in the same way as option
|
|
Packit |
3fa651 |
-- arguments.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- * Commands. A command defines a completely independent sub-parser. When a
|
|
Packit |
3fa651 |
-- command is encountered, the whole command line is passed to the
|
|
Packit |
3fa651 |
-- corresponding parser.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- See the "Parser Builders" section for how to construct and customise
|
|
Packit |
3fa651 |
-- these parsers.
|
|
Packit |
3fa651 |
Parser,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- ** Parser builders
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | This section contains utility functions and combinators to create parsers
|
|
Packit |
3fa651 |
-- for individual options.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- Each parser builder takes an option modifier. A modifier can be created by
|
|
Packit |
3fa651 |
-- composing the basic modifiers provided by here using the 'Monoid' operations
|
|
Packit |
3fa651 |
-- 'mempty' and 'mappend', or their aliases 'idm' and '<>'.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- For example:
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- > out = strOption
|
|
Packit |
3fa651 |
-- > ( long "output"
|
|
Packit |
3fa651 |
-- > <> short 'o'
|
|
Packit |
3fa651 |
-- > <> metavar "FILENAME" )
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- creates a parser for an option called \"output\".
|
|
Packit |
3fa651 |
flag,
|
|
Packit |
3fa651 |
flag',
|
|
Packit |
3fa651 |
switch,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
strOption,
|
|
Packit |
3fa651 |
option,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
strArgument,
|
|
Packit |
3fa651 |
argument,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
subparser,
|
|
Packit |
3fa651 |
hsubparser,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
abortOption,
|
|
Packit |
3fa651 |
infoOption,
|
|
Packit |
3fa651 |
helper,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- ** Modifiers
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | 'Parser' builders take a modifier, which represents a modification of the
|
|
Packit |
3fa651 |
-- properties of an option, and can be composed as a monoid.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- Contraints are often used to ensure that the modifiers can be sensibly applied.
|
|
Packit |
3fa651 |
-- For example, positional arguments can't be specified by long or short names,
|
|
Packit |
3fa651 |
-- so the 'HasName' constraint is used to ensure we have a flag or option.
|
|
Packit |
3fa651 |
Mod,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
short,
|
|
Packit |
3fa651 |
long,
|
|
Packit |
3fa651 |
help,
|
|
Packit |
3fa651 |
helpDoc,
|
|
Packit |
3fa651 |
value,
|
|
Packit |
3fa651 |
showDefaultWith,
|
|
Packit |
3fa651 |
showDefault,
|
|
Packit |
3fa651 |
metavar,
|
|
Packit |
3fa651 |
noArgError,
|
|
Packit |
3fa651 |
hidden,
|
|
Packit |
3fa651 |
internal,
|
|
Packit |
3fa651 |
style,
|
|
Packit |
3fa651 |
command,
|
|
Packit |
3fa651 |
commandGroup,
|
|
Packit |
3fa651 |
completeWith,
|
|
Packit |
3fa651 |
action,
|
|
Packit |
3fa651 |
completer,
|
|
Packit |
3fa651 |
idm,
|
|
Packit |
3fa651 |
mappend,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
OptionFields,
|
|
Packit |
3fa651 |
FlagFields,
|
|
Packit |
3fa651 |
ArgumentFields,
|
|
Packit |
3fa651 |
CommandFields,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- ** Readers
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | A reader is used by the 'option' and 'argument' builders to parse
|
|
Packit |
3fa651 |
-- the data passed by the user on the command line into a data type.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- The most common are 'str' which is used for 'String' like types,
|
|
Packit |
3fa651 |
-- including 'ByteString' and 'Text'; and 'auto', which uses the 'Read'
|
|
Packit |
3fa651 |
-- typeclass, and is good for simple types like 'Int' or 'Double'.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- More complex types can use the 'eitherReader' or 'maybeReader'
|
|
Packit |
3fa651 |
-- functions to pattern match or use a more expressive parser like a
|
|
Packit |
3fa651 |
-- member of the 'Parsec' family.
|
|
Packit |
3fa651 |
ReadM,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
auto,
|
|
Packit |
3fa651 |
str,
|
|
Packit |
3fa651 |
maybeReader,
|
|
Packit |
3fa651 |
eitherReader,
|
|
Packit |
3fa651 |
disabled,
|
|
Packit |
3fa651 |
readerAbort,
|
|
Packit |
3fa651 |
readerError,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Program descriptions
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- ** 'ParserInfo'
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | A 'ParserInfo' describes a command line program, used to generate a help
|
|
Packit |
3fa651 |
-- screen. Two help modes are supported: brief and full. In brief mode, only
|
|
Packit |
3fa651 |
-- an option and argument summary is displayed, while in full mode each
|
|
Packit |
3fa651 |
-- available option and command, including hidden ones, is described.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- A 'ParserInfo' should be created with the 'info' function and a set of
|
|
Packit |
3fa651 |
-- 'InfoMod' modifiers.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
info,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
ParserInfo(..),
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
InfoMod,
|
|
Packit |
3fa651 |
fullDesc,
|
|
Packit |
3fa651 |
briefDesc,
|
|
Packit |
3fa651 |
header,
|
|
Packit |
3fa651 |
headerDoc,
|
|
Packit |
3fa651 |
footer,
|
|
Packit |
3fa651 |
footerDoc,
|
|
Packit |
3fa651 |
progDesc,
|
|
Packit |
3fa651 |
progDescDoc,
|
|
Packit |
3fa651 |
failureCode,
|
|
Packit |
3fa651 |
noIntersperse,
|
|
Packit |
3fa651 |
forwardOptions,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Running parsers
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | The execParser family of functions are used to run parsers
|
|
Packit |
3fa651 |
execParser,
|
|
Packit |
3fa651 |
customExecParser,
|
|
Packit |
3fa651 |
execParserPure,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- ** Handling parser results manually
|
|
Packit |
3fa651 |
getParseResult,
|
|
Packit |
3fa651 |
handleParseResult,
|
|
Packit |
3fa651 |
parserFailure,
|
|
Packit |
3fa651 |
renderFailure,
|
|
Packit |
3fa651 |
overFailure,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- ** 'ParserPrefs'
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | A 'ParserPrefs' contains general preferences for all command-line
|
|
Packit |
3fa651 |
-- options, and should be built with the 'prefs' function.
|
|
Packit |
3fa651 |
prefs,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
ParserPrefs(..),
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
PrefsMod,
|
|
Packit |
3fa651 |
multiSuffix,
|
|
Packit |
3fa651 |
disambiguate,
|
|
Packit |
3fa651 |
showHelpOnError,
|
|
Packit |
3fa651 |
showHelpOnEmpty,
|
|
Packit |
3fa651 |
noBacktrack,
|
|
Packit |
3fa651 |
columns,
|
|
Packit |
3fa651 |
defaultPrefs,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Completions
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- | optparse-applicative supplies a rich completion system for bash,
|
|
Packit |
3fa651 |
-- zsh, and fish shells.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- 'Completer' functions are used for option and argument to complete
|
|
Packit |
3fa651 |
-- their values.
|
|
Packit |
3fa651 |
--
|
|
Packit |
3fa651 |
-- Use the 'completer' builder to use these.
|
|
Packit |
3fa651 |
-- The 'action' and 'completeWith' builders are also provided for
|
|
Packit |
3fa651 |
-- convenience, to use 'bashCompleter' and 'listCompleter' as a 'Mod'.
|
|
Packit |
3fa651 |
Completer,
|
|
Packit |
3fa651 |
mkCompleter,
|
|
Packit |
3fa651 |
listIOCompleter,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
listCompleter,
|
|
Packit |
3fa651 |
bashCompleter,
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- * Types
|
|
Packit |
3fa651 |
ParseError(..),
|
|
Packit |
3fa651 |
ParserHelp(..),
|
|
Packit |
3fa651 |
ParserFailure(..),
|
|
Packit |
3fa651 |
ParserResult(..),
|
|
Packit |
3fa651 |
CompletionResult(..)
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
) where
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
-- reexport Applicative here for convenience
|
|
Packit |
3fa651 |
import Control.Applicative
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
import Options.Applicative.Common
|
|
Packit |
3fa651 |
import Options.Applicative.Builder
|
|
Packit |
3fa651 |
import Options.Applicative.Builder.Completer
|
|
Packit |
3fa651 |
import Options.Applicative.Extra
|
|
Packit |
3fa651 |
import Options.Applicative.Types
|
|
Packit |
3fa651 |
|
|
Packit |
3fa651 |
{-# ANN module "HLint: ignore Use import/export shortcut" #-}
|