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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Multiarg.Mode.Internal

Description

Internal functions used by Multiarg.Mode. You don't have to worry about "breaking" anything by using this module; it is separate from Multiarg.Mode primarily to tidy up the documentation in that module. The functions in Multiarg.Mode should satisfy most use cases. However, if you want more control over error handling, you can use this module.

Synopsis

Documentation

newtype ModeName Source

Constructors

ModeName String 

data ParsedMode a Source

Constructors

ModeGood a 
ModeError [OptionError] (Either OptionError OptName)

There was an error. There may be zero or more initial OptionError. There must be at least one error, which is either an OptionError or the name of an option, if the error is that there were not enough words following the option to provide it with its necessary arguments.

Instances

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.

Constructors

Mode ModeName ([Word] -> ParsedMode r) 

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 GlobalLocal g r Source

Instances

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

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) 

combine Source

Arguments

:: Either (OptionError, [OptionError]) [g]

Global result. Contains either one or more errors, or global option results.

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

Result of parsing mode word, and the mode options and positional arguments. May be Left a, where a is one or more errors, or Right b, where b is a good result. A good result b may be either Left c, where c is a list of positional arguments, or Right d, where d is the mode result. c indicates that no mode was recognized and may be either [], which indicates that the user passed no words at all after the global options, or x:xs, indicating that the user did pass words after the global options, but the first word was not recognized as a mode.

-> Either (String, [String]) (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.

parseModeLineWithErrors Source

Arguments

:: [OptSpec g]

Global options

-> [Mode r]

All modes

-> [String]

All command line tokens

-> GlobalLocal g r 

findExactMode :: Word -> [Mode a] -> Maybe (Mode a) Source

Takes a token and a list of all modes; returns the matching mode if there is one, or Nothing if there is no match.