Arg package:cmdargs
An unnamed argument. Anything not starting with
- is
considered an argument, apart from
"-" which is considered to
be the argument
"-", and any arguments following
"--". For example:
programname arg1 -j - --foo arg3 -- -arg4 --arg5=1 arg6
Would have the arguments:
["arg1","-","arg3","-arg4","--arg5=1","arg6"]
Describes whether an option takes an argument or not, and if so how
the argument is injected into a value of type a.
What to do with options following non-options.
Changes: Only
Permute is allowed, both
RequireOrder and
ReturnInOrder have been removed.
Is at least one of these arguments required, the command line will
fail if none are set
The type of data for the argument, i.e. FILE/DIR/EXT
A way of processing the argument.
Flag: "Put the nth non-flag argument here."
This field should be used to store a particular argument position
(0-based).
{hello = def &= argPos 0}
Flag: "Put non-flag arguments here."
All argument flags not captured by
argPos are returned by
args.
{hello = def &= args}
Command line argument processing
This library provides an easy way to define command line parsers. Most
users will want to use the
System.Console.CmdArgs.Implicit
module, whose documentation contains an example.
- System.Console.CmdArgs.Explicit provides a way to write
command line parsers for both single mode programs (most programs) and
multiple mode programs (e.g. darcs or cabal). Parsers are defined by
constructing a data structure.
- System.Console.CmdArgs.Implicit provides a way to concisely
define command line parsers, up to three times shorter than getopt.
These parsers are translated into the Explicit data type.
- System.Console.CmdArgs.GetOpt provides a wrapper allowing
compatiblity with existing getopt parsers, mapping to the Explicit
data type.
For a general reference on what command line flags are commonly used,
see
http://www.faqs.org/docs/artu/ch10s05.html.
This module re-exports the implicit command line parser.
Expand
@ directives in a list of arguments, usually obtained
from
getArgs. As an example, given the file
test.txt
with the lines
hello and
world:
expandArgsAt ["@test.txt","!"] == ["hello","world","!"]
Any
@ directives in the files will be recursively expanded
(raising an error if there is infinite recursion).
To supress
@ expansion, pass any
@ arguments after
--.
Create an argument flag, with an update function and the type of the
argument.
Given a sequence of arguments, join them together in a manner that
could be used on the command line, giving preference to the Windows
cmd shell quoting conventions.
For an alternative version, intended for actual running the result in
a shell, see "System.Process.showCommandForUser"
The unnamed arguments, a series of arguments, followed optionally by
one for all remaining slots
Process the flags obtained by
getArgs and
expandArgsAt with a mode. Displays an error and exits
with failure if the command line fails to parse, or returns the
associated value. Implemented in terms of
process. This
function makes use of the following environment variables:
- $CMDARGS_COMPLETE - causes the program to produce
completions using complete, then exit. Completions are based on
the result of getArgs, the index of the current argument is
taken from $CMDARGS_COMPLETE (set it to - to
complete the last argument), and the index within that argument is
taken from $CMDARGS_COMPLETE_POS (if set).
- $CMDARGS_HELPER/$CMDARGS_HELPER_PROG -
uses the helper mechanism for entering command line programs as
described in System.Console.CmdArgs.Helper.
Given a string, split into the available arguments. The inverse of
joinArgs.
A structure to store the additional data relating to --help,
--version, --quiet and --verbose.
Perform the necessary actions dictated by a
CmdArgs structure.
Just if --help is given, then gives the help message
for display, including a trailing newline.