{-|
This module constructs command lines. You may either use the helper functions
('flagNone', 'flagOpt', 'mode' etc.) or construct the type directly. These
types are intended to give all the necessary power to the person constructing
a command line parser.
For people constructing simpler command line parsers, the module
"System.Console.CmdArgs.Implicit" may be more appropriate.
As an example of a parser:
> arguments :: Mode [(String,String)]
> arguments = mode "explicit" [] "Explicit sample program" (flagArg (upd "file") "FILE")
> [flagOpt "world" ["hello","h"] (upd "world") "WHO" "World argument"
> ,flagReq ["greeting","g"] (upd "greeting") "MSG" "Greeting to give"
> ,flagHelpSimple (("help",""):)]
> where upd msg x v = Right $ (msg,x):v
And this can be invoked by:
> main = do
> x <- processArgs arguments
> if ("help","") `elem` xs then
> print $ helpText def arguments
> else
> print x
/Groups/: The 'Group' structure allows flags/modes to be grouped for the purpose of
displaying help. When processing command lines, the group structure is ignored.
/Modes/: The Explicit module allows multiple mode programs by placing additional modes
in 'modeGroupModes'. Every mode is allowed sub-modes, and thus multiple levels of mode
may be created. Given a mode @x@ with sub-modes @xs@, if the first argument corresponds
to the name of a sub-mode, then that sub-mode will be applied. If not, then the arguments
will be processed by mode @x@. Consequently, if you wish to force the user to explicitly
enter a mode, simply give sub-modes, and leave 'modeArgs' as @Nothing@. Alternatively, if
you want one sub-mode to be selected by default, place all it's flags both in the sub-mode
and the outer mode.
-}moduleSystem.Console.CmdArgs.Explicit(-- * Running command linesmoduleSystem.Console.CmdArgs.Explicit.Process,-- * Constructing command linesmoduleSystem.Console.CmdArgs.Explicit.Type,moduleSystem.Console.CmdArgs.Explicit,-- * Displaying helpmoduleSystem.Console.CmdArgs.Explicit.Help)whereimportSystem.Console.CmdArgs.Explicit.TypeimportSystem.Console.CmdArgs.Explicit.ProcessimportSystem.Console.CmdArgs.Explicit.HelpimportSystem.Console.CmdArgs.DefaultimportSystem.Console.CmdArgs.TextimportSystem.Console.CmdArgs.VerbosityimportData.Char-- | Create a help flag triggered by @-?@/@--help@.flagHelpSimple::(a->a)->FlagaflagHelpSimplef=flagNone["help","?"]f"Display help message"-- | Create a help flag triggered by @-?@/@--help@. The user-- may optionally modify help by specifying the format, such as:---- > --help=all - help for all modes-- > --help=html - help in HTML format-- > --help=100 - wrap the text at 100 characters-- > --help=100,one - full text wrapped at 100 charactersflagHelpFormat::(HelpFormat->TextFormat->a->a)->FlagaflagHelpFormatf=(flagOpt""["help","?"]upd"""Display help message"){flagInfo=FlagOptRare""}whereupdsv=caseformatsofLefte->LefteRight(a,b)->Right$fabvformat::String->EitherString(HelpFormat,TextFormat)formatxs=foldl(\accx->eitherLeft(fx)acc)(Rightdef)(sepxs)wheresep=words.map(\x->ifx`elem`":,"then' 'elsetoLowerx)fx(a,b)=casexof"all"->Right(HelpFormatAll,b)"one"->Right(HelpFormatOne,b)"def"->Right(HelpFormatDefault,b)"html"->Right(a,HTML)"text"->Right(a,defaultWrap)_|allisDigitx->Right(a,Wrap$readx)_->Left"unrecognised help format, expected one of: all one def html text <NUMBER>"-- | Create a version flag triggered by @-V@/@--version@.flagVersion::(a->a)->FlagaflagVersionf=flagNone["version","V"]f"Print version information"-- | Create verbosity flags triggered by @-v@/@--verbose@ and-- @-q@/@--quiet@flagsVerbosity::(Verbosity->a->a)->[Flaga]flagsVerbosityf=[flagNone["verbose","v"](fLoud)"Loud verbosity",flagNone["quiet","q"](fQuiet)"Quiet verbosity"]