console-program- Interpret the command line and settings in a config file as commands and options

Safe HaskellSafe




This module contains functions to create option descriptions, together with their argument types.


Option descriptions

data Option a Source

A value of type Option a describes an option, that delivers a value to the program of type a.

option Source


:: [Char]

List of short option characters.

-> [String]

List of long option strings.

-> Type a

Type of option argument.

-> a

Default value when the option is not specified by the user.

-> String


-> Option a

The resulting option description.

Create an option description.

Options can have arguments, as in myprogram --foo=bar, where bar is the argument to foo. These arguments have types, dictated by the particular option; this type is the third parameter to option.

data Type a Source

A Type a represents the type of an option or argument.

Further below you can find some common types of option arguments.




parser :: String -> Either String a

Parse the option argument into a value (Right) or signal a parsing error (Left).

name :: String

A name for this type of option argument (for usage info).

defaultValue :: Maybe a

The default value when the option occurs without option argument. Nothing means that an argument is required for this type of option.


Argument types

optional Source


:: a

Default value.

-> Type a 
-> Type a 

string :: Type String Source

A plain string.

boolean :: Type Bool Source

A boolean. Argument can be "1","0","true","false","on","off","yes","no".

directory :: Type FilePath Source

A directory path. A trailing slash is stripped, if present.

file :: Type FilePath Source

A file path.

device :: Type FilePath Source

A device path.

natural :: Type Integer Source

A natural number (in decimal).

integer :: Type Integer Source

An integer number (in decimal).