Module

Options.Applicative.Types

Package
purescript-optparse
Repository
f-o-a-m/purescript-optparse

#ParserInfo Source

newtype ParserInfo a

A 'ParserInfo' describes a command line program, used to generate a help screen. Two help modes are supported: brief and full. In brief mode, only an option and argument summary is displayed, while in full mode each available option and command, including hidden ones, is described.

A basic 'ParserInfo' with default values for fields can be created using the 'info' function.

Constructors

Instances

#ParserPrefs Source

newtype ParserPrefs

Global preferences for a top-level 'Parser'. A 'ParserPrefs' contains general preferences for all command-line options, and can be built with the 'prefs' function.

Constructors

Instances

#Option Source

newtype Option a

A single option of a parser.

Constructors

Instances

#OptReader Source

data OptReader a

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

Constructors

Instances

#OptProperties Source

newtype OptProperties

Specification for an individual parser option.

Constructors

Instances

#OptVisibility Source

data OptVisibility

Visibility of an option in the help text.

Constructors

Instances

#ReadM Source

newtype ReadM a

A reader is used by the 'option' and 'argument' builders to parse the data passed by the user on the command line into a data type.

The most common are 'str' which is used for 'String', there are readers for Int, Number, Boolean.

More complex types can use the 'eitherReader' or 'maybeReader' functions to pattern match or use a more expressive parser like a member of the 'Parsec' family. A newtype over 'ReaderT String Except', used by option readers.

Constructors

Instances

#readerAsk Source

readerAsk :: ReadM String

Return the value being read.

#readerAbort Source

readerAbort :: forall a. ParseError -> ReadM a

Abort option reader by exiting with a 'ParseError'.

#readerError Source

readerError :: forall a. String -> ReadM a

Abort option reader by exiting with an error message.

#CReader Source

newtype CReader a

Constructors

Instances

#Parser Source

data Parser a

A 'Parser' is the core type in optparse-applicative. A value of type Parser a@ represents a specification for a set of options, which will yield a value of type a when the command line arguments are successfully parsed.

There are several types of primitive 'Parser'.

  • Flags: simple no-argument options. When a flag is encountered on the command line, its value is returned.

  • Options: options with an argument. An option can define a /reader/, which converts its argument from String to the desired value, or throws a parse error if the argument does not validate correctly.

  • Arguments: positional arguments, validated in the same way as option arguments.

  • Commands. A command defines a completely independent sub-parser. When a command is encountered, the whole command line is passed to the corresponding parser.

** Parser builders

Each parser builder takes an option modifier. A modifier can be created by composing the basic modifiers provided by here using the 'Monoid' operations mempty' and 'append', or their aliases 'idm' and '<>'.

For example:

out = strOption ( long "output" <> short 'o' <> metavar "FILENAME" )

creates a parser for an option called "output".

Constructors

Instances

#MultPE Source

data MultPE a x

Constructors

#Completer Source

newtype Completer

optparse-applicative supplies a rich completion system for bash, zsh, and fish shells.

'Completer' functions are used for option and argument to complete their values.

Use the 'completer' builder to use these. The 'action' and 'completeWith' builders are also provided for convenience, to use 'bashCompleter' and 'listCompleter' as a 'Mod'.

Constructors

Instances

#mkCompleter Source

mkCompleter :: (String -> Effect (Array String)) -> Completer

Smart constructor for a 'Completer'

#CompletionResult Source

#overFailure Source

#Args Source

#ArgPolicy Source

data ArgPolicy

Policy for how to handle options within the parse

Constructors

Instances

#OptHelpInfo Source

newtype OptHelpInfo

Constructors

Instances

#OptTree Source

data OptTree a

Constructors

Instances

#SomeParser Source

#Context Source

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

#optVisibility Source

#optMetaVar Source

optMetaVar :: forall a. Option a -> String

#optHelp Source

optHelp :: forall a. Option a -> Chunk Doc

#optShowDefault Source

optShowDefault :: forall a. Option a -> Maybe String

#optDescMod Source

optDescMod :: forall a. Option a -> Maybe (Doc -> Doc)

#many Source

many :: forall a. Parser a -> Parser (List a)

Parses 0 or more values using the given parser. Note: this should never be used with the value modifier.

For example, by using this option many (strOption (long "arg-name"))

one could write

command
# produces Nil

command --arg-name first
# produces ("first" : Nil)

command --arg-name first --arg-name second
# produces ("first" : "second" : Nil)

To parse 1 or more values, see some instead.

#some Source

some :: forall a. Parser a -> Parser (NonEmptyList a)

Parses 1 or more values using the given parser. Note: this should never be used with the value modifier.

For example, by using this option some (strOption (long "arg-name"))

one could write

command
# produces failure message

command --arg-name first
# produces (NonEmptyList "first" Nil)

command --arg-name first --arg-name second
# produces (NonEmptyList "first" ("second" : Nil))

To parse 0 or more values, see many instead.

#optional Source

optional :: forall f a. Alt f => Applicative f => f a -> f (Maybe a)

Re-exports from Options.Applicative.Help.Types

#ParserHelp Source

newtype ParserHelp

Constructors

Instances