cmdtheline-0.2.2: Declarative command-line option parsing and documentation library.

Safe HaskellSafe-Inferred

System.Console.CmdTheLine.ArgVal

Contents

Synopsis

Parsing values from the command line

type ArgParser a = String -> Either Doc aSource

The type of parsers of individual command line argument values.

type ArgPrinter a = a -> DocSource

The type of printers of values retrieved from the command line.

type Converter a = (ArgParser a, ArgPrinter a)Source

A converter is just a pair of a parser and a printer.

class ArgVal a whereSource

The class of values that can be converted from the command line.

pp :: ArgVal a => ArgPrinter aSource

The pretty printing part of a converter.

parser :: ArgVal a => ArgParser aSource

The parsing part of a converter.

Helpers for instantiating ArgVal

fromParsec :: (String -> Doc) -> Parsec String () a -> ArgParser aSource

fromParsec onErr p makes an ArgParser from p using onErr to produce meaningful error messages. On failure, onErr will receive a raw string of the value found on the command line.

enum :: Eq a => [(String, a)] -> Converter aSource

A converter of enumerated values conveyed as an association list of ( string, value ) pairs. Unambiguous prefixes of string map to value.

Maybe values

just :: ArgVal a => Converter (Maybe a)Source

A converter of Maybe values of ArgVal instances.

Parses as:

 fmap Just . parser

Pretty prints as:

 maybe empty pp

List values

list :: ArgVal a => Char -> Converter [a]Source

list sep creates a converter of lists of an ArgVal instance separated by sep.

Tuple values

pair :: (ArgVal a, ArgVal b) => Char -> Converter (a, b)Source

pair sep creates a converter of pairs of ArgVal instances separated by sep.

triple :: (ArgVal a, ArgVal b, ArgVal c) => Char -> Converter (a, b, c)Source

triple sep creates a converter of triples of ArgVal instances separated by sep.

quadruple :: (ArgVal a, ArgVal b, ArgVal c, ArgVal d) => Char -> Converter (a, b, c, d)Source

quadruple sep creates a converter of quadruples of ArgVal instances separated by sep.

quintuple :: (ArgVal a, ArgVal b, ArgVal c, ArgVal d, ArgVal e) => Char -> Converter (a, b, c, d, e)Source

quintuple sep creates a converter of quintuples of ArgVal instances separated by sep.