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

Safe HaskellNone




This module contains functions to build a console program, that parses the command line (and a configuration file), divides it into commands, options and non-options, and executes the corresponding action from a tree of available commands.

These commands can be constructed using the module System.Console.Command.


Using a command tree to construct a program

single :: (MonadIO m, Applicative m) => Commands m -> m () Source #

Load the configuration file (if present), and run the command given on the command line. Settings on the command line override the configuration file.

You may use this function, applied to your tree of available commands, as your main function.

interactive :: (MonadIO m, MonadException m, Applicative m) => Commands m -> m () Source #

Start an interactive session. Arguments to the program are ignored; instead, the user may repeatedly enter a command, possibly with options, which will be executed.

interactiveWithPrompt :: (MonadIO m, MonadException m, Applicative m) => m String -> Commands m -> m () Source #

Same as interactive, but with a custom monadic function specifying the text of the prompt.

showUsage :: MonadIO m => Commands n -> m () Source #

Print usage info for the program to stdout.

Configuration file

The configuration file is assumed to be in the user's home directory, and to be named ".foobar/config", where "foobar" is the name of the root of the command tree (usually the name of the program).

Settings in this file are of the form option-name=option-value The format of the "option-value" part depends on the type of the option argument; see System.Console.Argument.

Sections can be defined for settings applying to a single command, using the name of a command, enclosed in square brackets, as section header: [command1] option-for-command1=true .