multiarg-0.30.0.8: Command lines for options that take multiple arguments

Safe HaskellSafe-Inferred
LanguageHaskell2010

Multiarg.Mode

Description

Helps you build command-line parsers for programs that have more than one so-called mode; examples of such programs include git, darcs, and ghc-pkg.

Synopsis

Documentation

data ArgSpec a Source

Specifies how many option arguments an option takes.

Constructors

ZeroArg a

This option takes no option arguments

OneArg (String -> a)

This option takes one option argument

TwoArg (String -> String -> a)

This option takes two option arguments

ThreeArg (String -> String -> String -> a)

This option takes three option arguments

Instances

data OptSpec a Source

Specifies an option. Typically you will use optSpec to create an OptSpec rather than using the constructor directly. Each OptSpec may contain mulitple short option names and long option names; but each OptSpec contains only one ArgSpec. Therefore, all short option names and long option names specified in a single OptSpec are synonymous.

Instances

optSpec Source

Arguments

:: [Char]

There is one character for each desired short option name. Each of these characters may not be a hyphen; otherwise, optSpec will apply error.

-> [String]

There is one string for each desired long option name. Each string:

  • cannot be empty;
  • must not begin with a hyphen; and
  • must not contain an equal sign.

Otherwise, optSpec will apply error.

-> ArgSpec a

How many option arguments this option takes. This also specifies what is returned when the option is parsed on the command line.

-> OptSpec a 

Creates an OptSpec.

data Mode r Source

A Mode represents a single command line mode, such as check for ghc-pkg check. It contains the name of the mode, as well as a parser that handles all options and positional arguments for the mode. Ordinarily you will create a Mode using the mode function rather than by using the constructor directly.

Instances

mode Source

Arguments

:: String

Mode name. For instance, for the check mode of ghc-pkg, this would be check.

-> [OptSpec a]

Mode options

-> (String -> a)

Parses positional arguments

-> ([a] -> r)

Processes the result of all mode options

-> Mode r 

Creates a new Mode.

data ModeResult g r Source

The result of parsing a mode command line.

Constructors

ModeResult [g] (Either [String] r)

ModeResult a b is a successfully parsed mode command line, where:

a is a list of all global options parsed; and

b indicates the result of parsing the mode. It is Either c d, where Left c indicates that no mode was parsed. This arises under two circumstances. If the user did not include any words after the global options, then c will be the empty list, []. If the user did include words after the global options, but the first word was not recognized as a mode, then this list will contain the first word and any subsequent words. Therefore, note that if the user attempted to use a mode that does not exist (e.g. she misspelled it), this is not treated as an error. It's up to the client code to deal with this issue (for instance, your program might not view this situation as being an error.)

If b is Right d, this indicates that the user entered a recognized mode, and the result is d.

Instances

(Eq g, Eq r) => Eq (ModeResult g r) 
(Ord g, Ord r) => Ord (ModeResult g r) 
(Show g, Show r) => Show (ModeResult g r) 

parseModeLine Source

Arguments

:: [OptSpec g]

Global options. This might, for example, include a --help option.

-> [Mode r]

All modes

-> [String]

All command line words

-> Either (String, [String]) (ModeResult g r)

Returns Either a b. Left a represents an error. Each String represents a single error (this is returned as a pair because there must be at least one error; a simple list would not reflect this requirement.)

Right b indicates that parsing proceeded successfully; consult ModeResult to see what is returned.

Parses a command line that may contain modes.