This module is meant to eventually replace Command.Spec
, because the types are
easier to understand.
the help text for the command
the subcommand path of the command
the subcommand path of the command
the arguments passed to the command
flag name spec ~doc
specifies a command that, among other things, takes a flag
named name
on its command line. doc
indicates the meaning of the flag.
All flags must have a dash at the beginning of the name. If name
is not prefixed
by "-", it will be normalized to "-" ^ name
.
Unless full_flag_required
is used, one doesn't have to pass name
exactly on the
command line, but only an unambiguous prefix of name
(i.e., a prefix which is not
a prefix of any other flag's name).
NOTE: the doc
for a flag which takes an argument should be of the form
arg_name ^ " " ^ description
where arg_name
describes the argument and
description
describes the meaning of the flag.
NOTE: flag names (including aliases) containing underscores will be rejected. Use dashes instead.
NOTE: "-" by itself is an invalid flag name and will be rejected.
Beware that an anonymous argument of type int
cannot be specified as negative,
as it is ambiguous whether -1 is a negative number or a flag. If you need to pass
a negative number to your program, make it a parameter to a flag.
Beware that an anonymous argument of type int
cannot be specified as negative,
as it is ambiguous whether -1 is a negative number or a flag. If you need to pass
a negative number to your program, make it a parameter to a flag.
no_arg
flags may be passed at most once. The boolean returned
is true iff the flag is passed on the command line
no_arg_register ~key ~value
is like no_arg
, but associates value
with key
in the in the auto-completion environment
no_arg_abort ~exit
is like no_arg
, but aborts command-line parsing
by calling exit
. This flag type is useful for "help"-style flags that
just print something and exit.
escape
flags may be passed at most once. They cause the command line parser to
abort and pass through all remaining command line arguments as the value of the
flag.
A standard choice of flag name to use with escape
is "--"
.
(name %: typ)
specifies a required anonymous argument of type typ
.
The name
must not be surrounded by whitespace, if it is, an exn will be raised.
If the name
is surrounded by a special character pair (<>, {}, [] or (),)
name
will remain as-is, otherwise, name
will be uppercased.
In the situation where name
is only prefixed or only suffixed by one of the
special character pairs, or different pairs are used, (e.g. "<ARG") an exn will
be raised.
The (possibly transformed) name
is mentioned in the generated help for the
command.
t2
, t3
, and t4
each concatenate multiple anonymous argument
specs into a single one. The purpose of these combinators is to allow
for optional sequences of anonymous arguments. Consider a command with
usage:
main.exe FOO [BAR BAZ]
where the second and third anonymous arguments must either both be there or both not be there. This can be expressed as:
t2 ("FOO" %: foo) (maybe (t2 ("BAR" %: bar) ("BAZ" %: baz)))]
Sequences of 5 or more anonymous arguments can be built up using nested tuples:
maybe (t3 a b (t3 c d e))