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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Multiarg.Examples.Grover

Description

Grover is a simple example program that shows how to write a parser for commands with multiple modes. You build such parsers using Multiarg.Mode. It provides an example for the documentation, and it also provides fodder for the QuickCheck tests. You will want to look at the source code.

Grover has three modes: int, string, and maybe. Each of these modes has three options: -z or --zero, which takes no arguments; -s or --single, which takes one argument; -d or --double, which takes two arguments; and -t or --triple, which takes three arguments. The type of the argument depends on the mode. For int, the argument or arguments must be an integer; for string the arguments can be any string; and for maybe the arguments must be a Maybe Int, such as Nothing or Just 5.

Each mode also accepts any number of positional arguments, which can be any string.

Grover handles simple errors right inside the parser by using the Either type as a return value.

Synopsis

Documentation

data Global Source

Grover's global options.

Constructors

Help 
Verbose Int

The Int would indicate, for example, the desired level of verbosity.

Version 

Instances

data GroverOpt a Source

Handles all options and positional arguments for any Grover mode.

Constructors

Zero 
Single a 
Double a a 
Triple a a a 
PosArg String 

Instances

Functor GroverOpt 
Eq a => Eq (GroverOpt a) 
Ord a => Ord (GroverOpt a) 
Show a => Show (GroverOpt a) 

globalOptSpecs :: [OptSpec (Either String Global)] Source

All of Grover's global options. The OptSpec is parameterized on an Either to allow for error handling. If the user enters a non-integer argument for the --verbose option, a Left with an error message is returned.

modeOptSpecs :: Read a => [OptSpec (Either String (GroverOpt a))] Source

A list of OptSpec that works for any Mode.

data Result Source

Holds the results of parsing Grover's modes.

Instances

modes :: [Mode Result] Source

All Grover modes.

readErr :: Read a => String -> Either String a Source

Reads a value. If it cannot be read, returns an error message.

parseGrover Source

Arguments

:: [String]

Command line arguments, presumably from getArgs

-> Either (String, [String]) (ModeResult (Either String Global) Result)

Returns a Left if there are errors, or a Right if there are no errors. (In an actual application, further processing of a Right would be necessary to determine whether all entered arguments were valid.)

Parses all of Grover's options and modes.