cmdargs

System.Console.CmdArgs.Explicit.Type

Synopsis

- type Name = String
- type Help = String
- type FlagHelp = String
- parseBool :: String -> Maybe Bool
- data Group a = Group {
  - groupUnnamed :: [a]
  - groupHidden :: [a]
  - groupNamed :: [(Help, [a])]
  }
- fromGroup :: Group a -> [a]
- toGroup :: [a] -> Group a
- data Mode a = Mode {
  - modeGroupModes :: Group (Mode a)
  - modeNames :: [Name]
  - modeValue :: a
  - modeCheck :: a -> Either String a
  - modeReform :: a -> Maybe [String]
  - modeHelp :: Help
  - modeHelpSuffix :: [String]
  - modeArgs :: ([Arg a], Maybe (Arg a))
  - modeGroupFlags :: Group (Flag a)
  }
- modeModes :: Mode a -> [Mode a]
- modeFlags :: Mode a -> [Flag a]
- data FlagInfo
  - = FlagReq
  - | FlagOpt String
  - | FlagOptRare String
  - | FlagNone
- fromFlagOpt :: FlagInfo -> String
- type Update a = String -> a -> Either String a
- data Flag a = Flag {
  - flagNames :: [Name]
  - flagInfo :: FlagInfo
  - flagValue :: Update a
  - flagType :: FlagHelp
  - flagHelp :: Help
  }
- data Arg a = Arg {
  - argValue :: Update a
  - argType :: FlagHelp
  - argRequire :: Bool
  }
- checkMode :: Mode a -> Maybe String
- class Remap m where
  - remap :: (a -> b) -> (b -> (a, a -> b)) -> m a -> m b
- remap2 :: Remap m => (a -> b) -> (b -> a) -> m a -> m b
- modeEmpty :: a -> Mode a
- mode :: Name -> a -> Help -> Arg a -> [Flag a] -> Mode a
- modes :: String -> a -> Help -> [Mode a] -> Mode a
- flagNone :: [Name] -> (a -> a) -> Help -> Flag a
- flagOpt :: String -> [Name] -> Update a -> FlagHelp -> Help -> Flag a
- flagReq :: [Name] -> Update a -> FlagHelp -> Help -> Flag a
- flagArg :: Update a -> FlagHelp -> Arg a
- flagBool :: [Name] -> (Bool -> a -> a) -> Help -> Flag a

# Documentation

type Name = String

A name, either the name of a flag (`--foo`) or the name of a mode.

type Help = String

A help message that goes with either a flag or a mode.

type FlagHelp = String

The type of a flag, i.e. `--foo=TYPE`.

parseBool :: String -> Maybe Bool

Parse a boolean, accepts as True: true yes on enabled 1.

data Group a

A group of items (modes or flags). The items are treated as a list, but the group structure is used when displaying the help message.

Constructors

Group |

Fields

groupUnnamed :: [a]

  Normal items.

groupHidden :: [a]

  Items that are hidden (not displayed in the help message).

groupNamed :: [(Help, [a])]

  Items that have been grouped, along with a description of each group.

Instances

Functor Group |
Show a => Show (Group a) |
Monoid (Group a) |
Packer a => Packer (Group a) |

fromGroup :: Group a -> [a]

Convert a group into a list.

toGroup :: [a] -> Group a

Convert a list into a group, placing all fields in `groupUnnamed`.

data Mode a

A mode. Each mode has three main features:

- A list of submodes (`modeGroupModes`)
- A list of flags (`modeGroupFlags`)
- Optionally an unnamed argument (`modeArgs`)

Constructors

Mode |

Fields

modeGroupModes :: Group (Mode a)

  The available sub-modes

modeNames :: [Name]

  The names assigned to this mode (for the root mode, this name is used as the program name)

modeValue :: a

  Value to start with

modeCheck :: a -> Either String a

  Check the value reprsented by a mode is correct, after applying all flags

modeReform :: a -> Maybe [String]

  Given a value, try to generate the input arguments.

modeHelp :: Help

  Help text

modeHelpSuffix :: [String]

  A longer help suffix displayed after a mode

modeArgs :: ([Arg a], Maybe (Arg a))

  The unnamed arguments, a series of arguments, followed optionally by one for all remaining slots

modeGroupFlags :: Group (Flag a)

  Groups of flags

Instances

Remap Mode |
Show (Mode a) |
Packer a => Packer (Mode a) |

modeModes :: Mode a -> [Mode a]

Extract the modes from a `Mode`

modeFlags :: Mode a -> [Flag a]

Extract the flags from a `Mode`

data FlagInfo

The `FlagInfo` type has the following meaning:

                  FlagReq     FlagOpt      FlagOptRare/FlagNone
     -xfoo        -x=foo      -x=foo       -x -foo
     -x foo       -x=foo      -x foo       -x foo
     -x=foo       -x=foo      -x=foo       -x=foo
     --xx foo     --xx=foo    --xx foo     --xx foo
     --xx=foo     --xx=foo    --xx=foo     --xx=foo

Constructors

FlagReq | Required argument
FlagOpt String | Optional argument
FlagOptRare String | Optional argument that requires an = before the value
FlagNone | No argument

Instances

Eq FlagInfo |
Ord FlagInfo |
Show FlagInfo |
Packer FlagInfo |

fromFlagOpt :: FlagInfo -> String

Extract the value from inside a `FlagOpt` or `FlagOptRare`, or raises an error.

type Update a = String -> a -> Either String a

A function to take a string, and a value, and either produce an error message (`Left`), or a modified value (`Right`).

data Flag a

A flag, consisting of a list of flag names and other information.

Constructors

Flag |

Fields

flagNames :: [Name]

  The names for the flag.

flagInfo :: FlagInfo

  Information about a flag's arguments.

flagValue :: Update a

  The way of processing a flag.

flagType :: FlagHelp

  The type of data for the flag argument, i.e. FILE/DIR/EXT

flagHelp :: Help

  The help message associated with this flag.

Instances

Remap Flag |
Show (Flag a) |
Packer a => Packer (Flag a) |

data Arg a

An unnamed argument. Anything not starting with `-` is considered an argument, apart from `"-"` which is considered to be the argument `"-"`, and any arguments following `"--"`. For example:

     programname arg1 -j - --foo arg3 -- -arg4 --arg5=1 arg6

Would have the arguments:

     ["arg1","-","arg3","-arg4","--arg5=1","arg6"]

Constructors

Arg |

Fields

argValue :: Update a

  A way of processing the argument.

argType :: FlagHelp

  The type of data for the argument, i.e. FILE/DIR/EXT

argRequire :: Bool

  Is at least one of these arguments required, the command line will fail if none are set

Instances

Remap Arg |
Show (Arg a) |
Packer a => Packer (Arg a) |

checkMode :: Mode a -> Maybe String

Check that a mode is well formed.

class Remap m where

Methods

remap

Arguments

:: (a -> b) | Embed a value
-> (b -> (a, a -> b)) | Extract the mode and give a way of re-embedding
-> m a |
-> m b |

Instances

Remap Arg |
Remap Flag |
Remap Mode |

remap2 :: Remap m => (a -> b) -> (b -> a) -> m a -> m b

modeEmpty :: a -> Mode a

Create an empty mode specifying only `modeValue`. All other fields will usually be populated using record updates.

mode :: Name -> a -> Help -> Arg a -> [Flag a] -> Mode a

Create a mode with a name, an initial value, some help text, a way of processing arguments and a list of flags.

modes :: String -> a -> Help -> [Mode a] -> Mode a

Create a list of modes, with a program name, an initial value, some help text and the child modes.

flagNone :: [Name] -> (a -> a) -> Help -> Flag a

Create a flag taking no argument value, with a list of flag names, an update function and some help text.

flagOpt :: String -> [Name] -> Update a -> FlagHelp -> Help -> Flag a

Create a flag taking an optional argument value, with an optional value, a list of flag names, an update function, the type of the argument and some help text.

flagReq :: [Name] -> Update a -> FlagHelp -> Help -> Flag a

Create a flag taking a required argument value, with a list of flag names, an update function, the type of the argument and some help text.

flagArg :: Update a -> FlagHelp -> Arg a

Create an argument flag, with an update function and the type of the argument.

flagBool :: [Name] -> (Bool -> a -> a) -> Help -> Flag a

Create a boolean flag, with a list of flag names, an update function and some help text.