Arg

list : Task (List Str) *

Gives a list of the program's command-line arguments.

NamedParser a

A parser for a command-line application.

A NamedParser is usually built from a Parser using program.

Parser a

Describes how to parse a slice of command-line arguments.

Parsers can be composed in various ways, including via withParser and subCommand.

Once you have a Parser that describes your application's entire parsing needs, consider transforming it into a NamedParser.

ParseError

Enumerates errors that can occur during parsing a list of command line arguments.

toHelp : Parser * -> Help

Generates help metadata from a Parser.

This is useful if you would like to use this metadata to generate your own human-readable help or hint menus.

A default help menu can be generated with formatHelp.

succeed : a -> Parser a

A parser that immediately succeeds with its given input.

program

Marks a Parser as the entry point for parsing a command-line application, taking the program name and optionally a high-level help message for the application.

The produced NamedParser can be used to parse arguments via parse or parseFormatted.

parse : NamedParser a, List Str -> Result a ParseError

Parses a list of command-line arguments with the given parser. The list of arguments is expected to contain the name of the program in the first position.

If the arguments do not conform with what is expected by the parser, the first error seen will be returned.

boolOption : -> Parser Bool

Creates a parser for a boolean option argument.

Options of value "true" and "false" will be parsed as Bool.true and Bool.false, respectively. All other values will result in a WrongOptionType error.

strOption : -> Parser Str

Creates a parser for a string option argument.

i64Option : -> Parser I64

Creates a parser for a 64-bit signed integer (I64) option argument.

str : -> Parser Str

Parses a single positional argument as a string.

subCommand : Parser a, Str -> { name : Str, parser : Parser a }

Wraps a given parser as a subcommand parser.

When parsing arguments, the subcommand name will be expected to be parsed first, and then the wrapped parser will be applied to the rest of the arguments.

To support multiple subcommands, use choice.

choice : List { name : Str, parser : Parser a } -> Parser a

Creates a parser that matches over a list of subcommands.

The given list of subcommands is expected to be non-empty, and unique in the subcommand name. These invariants are not enforced today, but may be in the future.

During argument parsing, the list of subcommands will be tried in-order. Due to the described invariant, at most one given subcommand will match any argument list.

parseFormatted

withParser

Applies one parser over another, mapping parser.

withParser mapper parser produces a parser that will parse an argument list with parser first, then parse the remaining list with mapper, and feed the result of parser to mapper.

This provides a way to chain the results of multiple parsers together. For example, to combine the results of two strOption arguments into a record, you could use

succeed (\host -> \port -> { host, port })
|> withParser (strOption { long: "host" })
|> withParser (strOption { long: "port" })