Modules for GNU getopt(3)
-style command line parsing.
This module contains the basic functions and types for defining new option types and accessing the values of options.
This exception signals that an option value is invalid. The first string contains the option string ('-x' or '--long-name') and the second string contains an error message.
This exception is only used when implementing custom option types and can never "escape" the scope of a OptParse.OptParser.parse. The user should therefore not attempt to catch it.
#
option_set
| : string -> string list -> unit | ; | |||
#
option_set_value
| : 'a -> unit | ; | |||
#
option_get
| : unit -> 'a option | ; | |||
#
option_metavars
| : string list | ; | |||
#
option_defhelp
| : string option | ; |
Option type.
option_set
is a closure which converts and records the value of
an option so that it can be retrieved with a later call to the
option_get
closure. It is called with the option name which was
given on the command line and a list of strings, each representing
one of the argument values given on the command line. It may raise
Option_error
if the value is invalid (for whatever reason).
option_set_value
is a closure which sets the value of an option
to a particular value.
option_get
is a closure which retrieves the recorded value
of the option. If the option value has not been set from the
command line, the default value is used. If there is no default
value, then None
should be returned.
option_metavars
is a list of "meta-variables" (arguments)
which this option accepts. This is mainly for display purposes,
but the length of this list determines how many arguments the
option parser accepts for this option (currently only lists of
length 0 or 1 are supported).
option_defhelp
is the default help string (if any). It is
used for displaying help messages whenever the user does not specify a help string manually when adding this
option. Using a non-None value here only makes sense for
completely generic options like OptParse.StdOpt.help_option.
Get the value of an option.
No_value
if no default values has been given
and the option value has not been set from the command line.
Get the value of an option as an optional value.
Some x
if the option has value x
(either by default or
from the command line). If the option doesn't have a value None
is returned.
Find out if the option has a value (either by default or from the command line).
True
iff the option has a value.
Make an option which takes a single argument.
value_option metavar default coerce errfmt
returns an option
which takes a single argument from the command line and calls
coerce
to coerce it to the proper type. If coerce
raises an
exception, exn
, then errfmt exn argval
is called to generate
an error message for display. metavar
is the name of the
metavariable of the option.
default
is the default value of the option. If None
, the the
option has no default value.
Make a callback option which takes a single argument.
callback_option metavar coerce errfmt f
returns an option which
takes a single argument from the command line and calls coerce
to coerce it to the proper type. If coerce
raises an exception
errfmt exn argval
is called to format an error message for
display. If coerce
succeeds, the callback function f
is called
with the coerced value. Finally, metavar
is the name of the
metavariable of the option.
This module contains various standard options.
Create a counting option which increments its value each time the option is encountered on the command line.
Exactly identical to count_option ~dest:dest ~increment:1 ()
.
Exactly identical to count_option ~dest:dest ~increment:(-1) ()
.
See OptParse.StdOpt.int_option.
See OptParse.StdOpt.int_option.
See OptParse.StdOpt.int_callback.
See OptParse.StdOpt.int_callback.
This module contains the types and functions for implementing custom usage message formatters.
#
indent
| : unit -> unit | ; | (* | Increase the indentation level. | *) |
#
dedent
| : unit -> unit | ; | (* | Decrease the indentation level. | *) |
#
format_usage
| : string -> string | ; | (* | Format usage string into style of this formatter. | *) |
#
format_heading
| : string -> string | ; | (* | Format heading into style of this formatter. | *) |
#
format_description
| : string -> string | ; | (* | Format description into style of this formatter. | *) |
#
format_option
| : char list * string list -> string list -> string option -> string | ; | (* | Format option into style of this formatter (see explanation below). | *) |
This is the type of a formatter. The format_option
has
signature format_option (snames,lnames) metavars help
, where
snames
is a list of the short option names, lnames
is a
list of the long option names, metavars
is a list of the
metavars the option takes as arguments, and help
is the help
string supplied by the user.
Create an "indented" formatter with the given options.
Creates a titled formatter which is quite similar to the indented formatter. See OptParse.Formatter.indented_formatter for a description of the options.
wrap text width
reflows the given text paragraph into lines
of width at most width
(lines may exceed this if the are
single words that exceed this limit).
This module contains the option parser itself.
It provides functions to create, populate and use option parsers to parse command line arguments.
The type of an option parser.
The type of an option group.
Creates a new option parser with the given options.
"%prog"
in usage
is replaced with the name of the program
(see prog
).
version
to be printed to the standard output and the
program to exit.
Add an option to the option parser.
Option_conflict
if the short name(s) or long name(s)
have alread been used for some other option.
'x'
means that the option is invoked with -x
on the
command line).
short_name
).
"xyzzy"
means that the option is invoked with --xyzzy
on the command line).
long_name
).
Display an error message and exit the program. The error
message is printed to the channel chn
(default is
Pervasives.stderr
) and the program exits with exit status
status
(default is 1).
Display the usage message to the channel chn
(default is
Pervasives.stdout
) and return.