type spec = | Unit of (unit -> unit) (* Call the function with no argument *) | Set of bool ref (* Set the reference to true *) | Clear of bool ref (* Set the reference to false *) | String of (string -> unit) (* Call the function with a string argument *) | Int of (int -> unit) (* Call the function with an int argument *) | Float of (float -> unit) (* Call the function with a float argument *)
val parse : (string * spec * string) list -> (string -> unit) -> string -> unit
parse speclist anonfun errmsg parses the command line. speclist is a list of triples (key, spec, doc). key is the option keyword, it must start with a -. spec gives the option type and the function to call when this option is found on the command line. doc is a one-line description of this option. anonfun is called on anonymous arguments. The functions in spec and anonfun are called in the same order as their arguments appear on the command line.
If an error occurs, parse exits the program, after printing an error
message as follows:
The reason for the error: unknown option, invalid or missing argument, etc.
errmsg
The list of options, each followed by the corresponding doc string.
For the user to be able to specify anonymous arguments starting with a -, include for example ("--", String anonfun, doc) in speclist.
By default, parse recognizes a unit option -help, which will display errmsg and the list of options, and exit the program. You can override this behaviour by specifying your own -help option in speclist.
exception Bad of string
val usage: (string * spec * string) list -> string -> unit
usage speclist errmsg speclist and errmsg are the same as for parse. usage prints the same error message that parse prints in case of error.