-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Interprets the command line and a config file as commands and options
--
-- This library provides an infrastructure to build command line
-- programs. It provides the following features:
--
--
-- - declare any number of "actions" (commands, or modes of operation,
-- of the program);
-- - declare options of the program;
-- - collect options and actions from a configuration file and the
-- command line, and execute the proper action.
--
--
-- It provides functionality similar to the "cmdargs" package. Main
-- differences:
--
--
-- - console-program does not use unsafePerformIO, and tries to give a
-- more haskellish, referentially transparent interface;
-- - it allows a full tree of "modes", instead of a list, so a command
-- can have subcommands;
-- - it parses a configuration file, in addition to the command line
-- arguments.
--
@package console-program
@version 0.1.0.2
module System.Console.Argument
data Type a
Type :: (String -> String -> Either String a) -> String -> Maybe a -> Type a
parser :: Type a -> String -> String -> Either String a
name :: Type a -> String
defaultValue :: Type a -> Maybe a
optional :: a -> Type a -> Type a
-- | A plain string.
string :: Type String
-- | A boolean. Argument can be "1","0","true","false","on","off".
boolean :: Type Bool
-- | A directory path. A trailing slash is stripped, if present.
directory :: Type FilePath
-- | A file path.
file :: Type FilePath
-- | A device path.
device :: Type FilePath
-- | A natural number (in decimal).
natural :: Type Integer
-- | An integer number (in decimal).
integer :: Type Integer
-- | Create an option description.
option :: (a -> s) -> [Char] -> [String] -> Type a -> String -> OptDescr (Either String s)
instance Functor Type
module System.Console.Options
-- | An instance s of Setting has as values partial
-- sets of option assignments, as given by the user in a configuration
-- file or command line options. Options s is the
-- associated type of complete configurations, as the program peruses.
class Setting s where { type family Options s; }
set :: (Setting s) => s -> Options s -> Options s
apply :: (Setting s) => [s] -> Options s -> Options s
-- | create is a template haskell computation. Given names for the
-- "options" type, the "settings" type and the "set" function, and a list
-- of settings (pairs of their names and types), it creates those
-- datatypes and function, and an instance of the Settings
-- class.
create :: String -> String -> String -> [(String, Type)] -> Q [Dec]
data Type :: *
ConT :: Name -> Type
module System.Console.Action
data Action o
run :: Action o -> [String] -> o -> IO ()
readerT :: ReaderT o IO () -> Action o
-- | A simple action, taking no argument.
simple :: IO () -> Action o
-- | Create an action that takes an argument (non-option).
--
-- The type of argument is specified by the first parameter; these values
-- can be obtained from the module System.Console.Argument.
withArgument :: Type x -> (x -> Action o) -> Action o
module System.Console.Command
-- | Commands s is a tree of commands. It represents the whole set
-- of possible commands of a program.
type Commands setting = Tree (Command setting)
-- | A Command s is an action, together with some descriptive
-- information: name (this is the textual command that invokes the
-- action), description, and lists of applicable options and non-options.
-- s is the type of setting.
data Command s
Command :: String -> [String] -> [OptDescr (Either String s)] -> String -> Action (Options s) -> Command s
name :: Command s -> String
applicableNonOptions :: Command s -> [String]
applicableOptions :: Command s -> [OptDescr (Either String s)]
description :: Command s -> String
action :: Command s -> Action (Options s)
-- | Load the configuration file (if present), and run the action given on
-- the command line.
single :: (Setting s) => Options s -> Commands s -> IO ()
-- | Show usage info for the program.
showUsage :: Commands o -> IO ()
instance Ord (OptDescr a)
instance Eq (OptDescr a)