-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Declarative command-line option parsing and documentation library. -- -- CmdTheLine aims to remove tedium from the definition of command-line -- programs, producing usage and help with little effort. -- -- The inspiration was found in Daniel Bunzli's -- http://erratique.ch/software/cmdliner library. -- -- CmdTheLine uses applicative functors to provide a declarative, -- compositional mechanism for defining command-line programs by lifting -- regular Haskell functions over argument parsers. -- -- A tutorial can be found at -- http://elifrey.com/2012/07/23/CmdTheLine-Tutorial/. -- -- Suggestions, comments, and bug reports are appreciated. Please see the -- bug and issue tracker at http://github.com/eli-frey/cmdtheline. -- -- Changes since 0.1: -- --
-- fmap Just . parser ---- -- Pretty prints as: -- --
-- maybe empty pp --just :: ArgVal a => Converter (Maybe a) -- | list sep creates a converter of lists of an -- ArgVal instance separated by sep. list :: ArgVal a => Char -> Converter [a] -- | pair sep creates a converter of pairs of ArgVal -- instances separated by sep. pair :: (ArgVal a, ArgVal b) => Char -> Converter (a, b) -- | triple sep creates a converter of triples of -- ArgVal instances separated by sep. triple :: (ArgVal a, ArgVal b, ArgVal c) => Char -> Converter (a, b, c) -- | quadruple sep creates a converter of quadruples of -- ArgVal instances separated by sep. quadruple :: (ArgVal a, ArgVal b, ArgVal c, ArgVal d) => Char -> Converter (a, b, c, d) -- | quintuple sep creates a converter of quintuples of -- ArgVal instances separated by sep. quintuple :: (ArgVal a, ArgVal b, ArgVal c, ArgVal d, ArgVal e) => Char -> Converter (a, b, c, d, e) instance ArgVal (Maybe HelpFormat) instance ArgVal HelpFormat instance ArgVal (Maybe (Ratio Integer)) instance ArgVal (Ratio Integer) instance ArgVal (Maybe Double) instance ArgVal Double instance ArgVal (Maybe Float) instance ArgVal Float instance ArgVal (Maybe Integer) instance ArgVal Integer instance ArgVal (Maybe Int) instance ArgVal Int instance ArgVal (Maybe [Char]) instance ArgVal [Char] instance ArgVal (Maybe Bool) instance ArgVal Bool module System.Console.CmdTheLine.Arg -- | The type of command line arguments. data Arg a -- | Information about an optional argument. Exposes the folowing fields. -- --
-- inf =(optInfo [ "i", "insufflation" ])
-- { optName = "INSUFFERABLE"
-- , optDoc = "in the haunted house's harrow"
-- , optSec = "NOT FOR AUGHT"
-- }
--
--
-- Names of one character in length will be prefixed by - on the
-- command line, while longer names will be prefixed by --.
--
-- It is considered a programming error to provide an empty list of names
-- to optInfo.
optInfo :: [String] -> OptInfo
-- | Initialize a PosInfo. The fields posName,
-- posDoc, and posSec can then be manipulated
-- post-mortem, as in
--
--
-- inf = posInfo
-- { posName = "DEST"
-- , posDoc = "A destination for the operation."
-- , posSec = "DESTINATIONS"
-- }
--
--
-- The fields posName and posDoc must be non-empty
-- strings for the argument to be listed with its documentation under the
-- section posSec of generated help.
posInfo :: PosInfo
-- | Create a command line flag that can appear at most once on the command
-- line. Yields False in absence and True in presence.
flag :: OptInfo -> Arg Bool
-- | As flag but may appear an infinity of times. Yields a list of
-- Trues as long as the number of times present.
flagAll :: OptInfo -> Arg [Bool]
-- | vFlag v [ ( v1, ai1 ), ... ] is an argument that can
-- be present at most once on the command line. It takes on the value
-- vn when appearing as ain.
vFlag :: a -> [(a, OptInfo)] -> Arg a
-- | vFlagAll vs assoc is as vFlag except that it
-- can be present an infinity of times. In absence, vs is
-- yielded. When present, each value is collected in the order they
-- appear.
vFlagAll :: [a] -> [(a, OptInfo)] -> Arg [a]
-- | opt v ai is an optional argument that yields
-- v in absence, or an assigned value in presence. If the option
-- is present, but no value is assigned, it is considered a user-error
-- and usage is printed on exit.
opt :: ArgVal a => a -> OptInfo -> Arg a
-- | defaultOpt def v ai is as opt except if it is
-- present and no value is assigned on the command line, def is
-- the result.
defaultOpt :: ArgVal a => a -> a -> OptInfo -> Arg a
-- | optAll vs ai is like opt except that it yields
-- vs in absence and can appear an infinity of times. The values
-- it is assigned on the command line are accumulated in the order they
-- appear.
optAll :: (ArgVal a, Ord a) => [a] -> OptInfo -> Arg [a]
-- | defaultOptAll def vs ai is like optAll except
-- that if it is present without being assigned a value, the value
-- def takes its place in the list of results.
defaultOptAll :: (ArgVal a, Ord a) => a -> [a] -> OptInfo -> Arg [a]
-- | pos n v ai is an argument defined by the nth
-- positional argument on the command line. If absent the value
-- v is returned.
pos :: ArgVal a => Int -> a -> PosInfo -> Arg a
-- | revPos n v ai is as pos but counting from the
-- end of the command line to the front.
revPos :: ArgVal a => Int -> a -> PosInfo -> Arg a
-- | posAny vs ai yields a list of all positional arguments
-- or vs if none are present.
posAny :: ArgVal a => [a] -> PosInfo -> Arg [a]
-- | posLeft n vs ai yield a list of all positional
-- arguments to the left of the nth positional argument or
-- vs if there are none.
posLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
-- | posRight n vs ai is as posLeft except yielding
-- all values to the right of the nth positional argument.
posRight :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
-- | revPosLeft n vs ai is as posLeft except
-- n counts from the end of the command line to the front.
revPosLeft :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
-- | revPosRight n vs ai is as posRight except
-- n counts from the end of the command line to the front.
revPosRight :: ArgVal a => Int -> [a] -> PosInfo -> Arg [a]
-- | value arg makes arg into a Term.
value :: Arg a -> Term a
-- | required arg converts arg into a Term
-- such that it fails in the Nothing and yields a in the
-- Just.
--
-- This is used for required positional arguments. There is nothing
-- stopping you from using it with optional arguments, except that they
-- would no longer be optional and it would be confusing from a user's
-- perspective.
required :: Arg (Maybe a) -> Term a
-- | nonEmpty arg is a Term that fails if its result
-- is empty. Intended for non-empty lists of positional arguments.
nonEmpty :: Arg [a] -> Term [a]
-- | lastOf arg is a Term that fails if its result
-- is empty and evaluates to the last element of the resulting list
-- otherwise. Intended for lists of flags or options where the last takes
-- precedence.
lastOf :: Arg [a] -> Term a
module System.Console.CmdTheLine.Term
-- | eval args ( term, termInfo ) allows the user to pass
-- args directly to the evaluation mechanism. This is useful if
-- some kind of pre-processing is required. If you do not need to
-- pre-process command line arguments, use one of exec or
-- run. On failure the program exits.
eval :: [String] -> (Term a, TermInfo) -> IO a
-- | exec ( term, termInfo ) executes a command line
-- program, directly grabbing the command line arguments from the
-- environment and returning the result upon successful evaluation of
-- term. On failure the program exits.
exec :: (Term a, TermInfo) -> IO a
-- | run ( term, termInfo ) runs a term containing
-- an IO action, performs the action, and returns the result on
-- success. On failure the program exits.
run :: (Term (IO a), TermInfo) -> IO a
-- | unwrap args ( term, termInfo ) unwraps a Term
-- without handling errors. The intent is for use in testing of Terms
-- where the programmer would like to consult error state without the
-- program exiting.
unwrap :: [String] -> (Term a, TermInfo) -> IO (Either EvalExit a)
-- | evalChoice args mainTerm choices is analogous to
-- eval, but for programs that provide a choice of commands.
evalChoice :: [String] -> (Term a, TermInfo) -> [(Term a, TermInfo)] -> IO a
-- | Analogous to exec, but for programs that provide a choice of
-- commands.
execChoice :: (Term a, TermInfo) -> [(Term a, TermInfo)] -> IO a
-- | Analogous to run, but for programs that provide a choice of
-- commands.
runChoice :: (Term (IO a), TermInfo) -> [(Term (IO a), TermInfo)] -> IO a
-- | Analogous to unwrap, but for programs that provide a choice of
-- commands.
unwrapChoice :: [String] -> (Term a, TermInfo) -> [(Term a, TermInfo)] -> IO (Either EvalExit a)
-- | Information about the way a Term exited early. Obtained by
-- either unwraping or unwrapChoiceing some Term. Handy for
-- testing programs when it is undesirable to exit execution of the
-- entire program when a Term exits early.
data EvalExit
Help :: HelpFormat -> (Maybe String) -> EvalExit
Usage :: Doc -> EvalExit
Msg :: Doc -> EvalExit
Version :: EvalExit
instance Error EvalExit
module System.Console.CmdTheLine
-- | The underlying Applicative of the library. A Term represents
-- a value in the context of being computed from the command line
-- arguments.
data Term a
-- | Information about a Term. It is recommended that
-- TermInfos be created by customizing defTI, as in
--
--
-- termInfo = defTI
-- { termName = "caroline-no"
-- , termDoc = "carry a line off"
-- }
--
data TermInfo
TermInfo :: String -> String -> String -> String -> String -> [ManBlock] -> TermInfo
-- | The name of the command or program represented by the term. Defaults
-- to "".
termName :: TermInfo -> String
-- | Documentation for the term. Defaults to "".
termDoc :: TermInfo -> String
-- | The section under which to place the terms documentation. Defaults to
-- "COMMANDS".
termSec :: TermInfo -> String
-- | The section under which to place a term's argument's documentation by
-- default. Defaults to "OPTIONS".
stdOptSec :: TermInfo -> String
-- | A version string. Must be left blank for commands. Defaults to
-- "".
version :: TermInfo -> String
-- | A list of ManBlocks to append to the default
-- [ManBlock]. Defaults to [].
man :: TermInfo -> [ManBlock]
-- | A default TermInfo.
defTI :: TermInfo
-- | Any String argument to a ManBlock constructor may
-- contain the following significant forms for a limited kind of
-- meta-programing.
--
--