Module OptParse.OptParser


module OptParser: sig .. end
This module contains the option parser itself.

It provides functions to create, populate and use option parsers to parse command line arguments.



Exceptions

exception Option_conflict of string
Option_conflic name is raised by OptParse.OptParser.add when two different options are added with identical names. Usually this doesn't need to be caught since this error is usually easily fixed permanently by removing/renaming the conflicting option names.

Types

type t 
The type of an option parser.
type group 
The type of an option group.

Option parser creation

val make : ?usage:string ->
?description:string ->
?version:string ->
?suppress_usage:bool ->
?suppress_help:bool ->
?prog:string ->
?formatter:OptParse.Formatter.t -> unit -> t
Creates a new option parser with the given options.
Returns the new option parser.

usage : Usage message. The default is a reasonable usage message for most programs. Any occurrence of the substring "%prog" in usage is replaced with the name of the program (see prog).
version : Version string. If set, a '--version' option is automatically added. When encountered on the command line it causes version to be printed to the standard output and the program to exit.
suppress_usage : Suppress the usage message if set.
suppress_help : Suppress the 'help' option which is otherwise added by default.
prog : Program name. The default is the base name of the executable.
val add : t ->
?group:group ->
?help:string ->
?hide:bool ->
?short_name:char ->
?short_names:char list ->
?long_name:string -> ?long_names:string list -> 'a OptParse.Opt.t -> unit
Add an option to the option parser.
Raises Option_conflict if the short name(s) or long name(s) have alread been used for some other option.

help : Short help message describing the option (for the usage message).
hide : If true, hide the option from the usage message. This can be used to implement "secret" options which are not shown, but work just the same as regular options in all other respects.
short_name : is the name for the short form of the option (e.g. 'x' means that the option is invoked with -x on the command line).
short_names : is a list of names for the short form of the option (see short_name).
long_name : is the name for the long form of the option (e.g. "xyzzy" means that the option is invoked with --xyzzy on the command line).
long_names : is a list of names for the long form of the option (see long_name).
val add_group : t ->
?parent:group ->
?description:string -> string -> group
Add a group to the option parser.
Returns the new group.

parent : is the parent group (if any).
description : is a description of the group.

Output and error handling

val error : t ->
?chn:Pervasives.out_channel -> ?status:int -> string -> unit
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).
val usage : t -> ?chn:Pervasives.out_channel -> unit -> unit
Display the usage message to the channel chn (default is Pervasives.stdout) and return.

Option parsing

val parse : t ->
?first:int -> ?last:int -> string array -> string list
Parse arguments as if the arguments args.(first), args.(first+1), ..., args.(last) had been given on the command line. By default first is 0 and last is the index of the last element of the array.
val parse_argv : t -> string list
Parse all the arguments in Sys.argv.