console-program-0.4.2.3: Interpret the command line and a config file as commands and options

System.Console.Command

Description

A Command provides a mode of operation of your program. This allows a single program to provide many different pieces of functionality. The first argument to the program (or the first few, if it has subcommands) determines which command should be executed. (darcs and cabal are examples of programs with this behaviour.)

An Action represents an IO action, together with information about applicable options and non-option arguments.

Synopsis

# Documentation

type Commands m = Tree (Command m) Source #

Commands m is a tree of commands (with action in the monad m). It represents the whole set of possible commands of a program.

data Tree a #

Non-empty, possibly infinite, multi-way trees; also known as rose trees.

Constructors

 Node a (Forest a)
Instances

data Command m Source #

A Command m is an action (in the monad m), together with some descriptive information.

Constructors

 Command Fieldsname :: StringThis determines which command is executed.description :: StringFor usage info.action :: Action mThe actual action performed by this command.shorten :: BoolPrefer shortened subcommands over non-option arguments.

command :: String -> String -> Action m -> Command m Source #

Create a new command having a given name and action.

data Action m Source #

An Action m is an action (in the monad m), which may take arguments ("non-options") and options from the command line.

io :: MonadIO m => m () -> Action m Source #

A simple action, taking no argument, and having no options.

withNonOption :: MonadIO m => Type x -> (x -> Action m) -> Action m Source #

Create an action that takes an argument (non-option).

The type of argument is specified by the first parameter; such values can be obtained from the module System.Console.Argument.

withNonOptions :: MonadIO m => Type x -> ([x] -> Action m) -> Action m Source #

Create an action that takes all remaining non-option arguments.

The type of arguments is specified by the first parameter; such values can be obtained from the module System.Console.Argument.

withOption :: MonadIO m => Option a -> (a -> Action m) -> Action m Source #

Create an action that takes an option.

The first parameter is a description of the option; such a value can be constructed using option.

ignoreOption :: Option a -> Action m -> Action m Source #

Create an action that allows, but ignores, the given option.

This is especially useful if this option is given in the configuration file, but is meant for other commands; then this action will not give an error message about an unrecognised option.