module Argv:sig..end
"--" option terminates the options; anything that comes after it
is considered an argument and is the purview of this Kwapp.Argv module.
Command-line arguments are positional and are typically accessed by
calling Kwapp.getopt to split the command line into options (and their
values) and the command-line args, returned as a string list. You
can extract the args by pattern matching or by name by calling
Kwapp.argument.
The combinators work similarly to those for Options, but since
args are positional, the Argv combinators are applied in a single
chain, while the Option combinators are applied to a single option
at a atime, and multiple options are gathered in a list.
All combinators apply to the previous arg, but all those for a
given arg may come in any order (arg must come first).
Examples:
Argv.(empty +> arg "FILE")Argv.(empty +> arg "FILE" +> optional)Argv.(empty +> arg "FILE1" +> arg "FILE2")Argv.(empty +> arg "FILE1" +> arg "FILE2" +> optional)Argv.(empty +> arg "FILE1" +> arg "FILE2" +> rep)Argv.(empty +> arg "FILE1" +> arg "FILE2" +> optional +> rep)
argv (add an arg with arg name first): Argv.(empty +> optional)Argv.(empty +> arg "FILE1" +> rep +> arg "FILE2")type arg = {
|
name : |
(* |
name
| *) |
|
opt : |
(* |
optional
| *) |
|
def : |
(* |
default value of arg, if not given on the command line
| *) |
|
desc : |
(* |
description
| *) |
|
validate : |
(* |
validator
| *) |
|
hide : |
(* |
hidden in help strings?
| *) |
val string_of_arg : arg -> string
type argv = {
|
argv : |
|
rep : |
val string_of_argv : argv -> string
val empty : argvargv, which accepts no args.val any : argvargv that accepts zero or more arbitrary string args.val validate : argv -> unitvalidate argv: validate an argv.
Checks that the argv doesn't define a required arg after an optional arg.
You typically don't want to call this; Kwapp.getopt, Kwapp.Argv.check, and
Help.help all call Kwapp.Argv.validate for you.
Raises ReqAfter for a required option after an optional one
val (+>) : 'a -> ('a -> 'b) -> 'b(+>): infix operator to combine combinators
(arg,optional,valid,rep); really just right-associative
function composition.val arg : string -> argv -> argvarg name: define a command line argument with the name name.Failure on attempt to add an arg after a repeatable argval optional : argv -> argvoptional: make the argument optional.Failure if applied to no argval desc : string -> argv -> argvdesc description: give the argument a description.Failure if applied to no argval def : string -> argv -> argvdef d: : add a default value for an optional command-line arg.
Kwapp.argument will return this default if the option isn't given
on the command line.
Raises Failure if applied to no arg or if applied to a required arg
d : the defaultval valid : Valid.t -> argv -> argvvalid v: add a validator to the argument.Failure if applied to no argval rep : argv -> argvrep: make the final argument repeatable.
Only the final argument can be repeatable!
Raises Failure if applied to no arg or if applied to an argv whose last arg is already repeatable
val hide : argv -> argvhide: make this argument hidden.
A hidden argument will not be described in any help strings.
val check : argv -> Kwapp.parsedopts * string list -> unitcheck iargv (m,argv): check parsed command line to assure that
all required command-line arguments were provided, that there are
no mutually-exclusive option conflicts, and that all option
arguments validate.Invalid if option argument or command-line arg has an invalid typeWrongNumber if the wrong number of arguments was provided(m,argv) : argv : actual argv, typically from Kwapp.getoptm : parsed options, typically from Kwapp.getopt : argv -> argvsanshidden argv: remove the hidden args from argv.argv : the argv