Module Caml.Arg
type spec=|Unit of unit -> unitCall the function with unit argument
|Bool of bool -> unitCall the function with a bool argument
|Set of bool Stdlib.refSet the reference to true
|Clear of bool Stdlib.refSet the reference to false
|String of string -> unitCall the function with a string argument
|Set_string of string Stdlib.refSet the reference to the string argument
|Int of int -> unitCall the function with an int argument
|Set_int of int Stdlib.refSet the reference to the int argument
|Float of float -> unitCall the function with a float argument
|Set_float of float Stdlib.refSet the reference to the float argument
|Tuple of spec listTake several arguments according to the spec list
|Symbol of string list * string -> unitTake one of the symbols as argument and call the function with the symbol
|Rest of string -> unitStop interpreting keywords and call the function with each remaining argument
|Expand of string -> string arrayIf the remaining arguments to process are of the form
["-foo"; "arg"] @ restwhere "foo" is registered asExpand f, then the argumentsf "arg" @ restare processed. Only allowed inparse_and_expand_argv_dynamic.The concrete type describing the behavior associated with a keyword.
val parse : (key * spec * doc) list -> anon_fun -> usage_msg -> unitArg.parse speclist anon_fun usage_msgparses the command line.speclistis a list of triples(key, spec, doc).keyis the option keyword, it must start with a'-'character.specgives the option type and the function to call when this option is found on the command line.docis a one-line description of this option.anon_funis called on anonymous arguments. The functions inspecandanon_funare called in the same order as their arguments appear on the command line.If an error occurs,
Arg.parseexits the program, after printing to standard error an error message as follows:- The reason for the error: unknown option, invalid or missing argument, etc.
usage_msg- The list of options, each followed by the corresponding
docstring. Beware: options that have an emptydocstring will not be included in the list.
For the user to be able to specify anonymous arguments starting with a
-, include for example("-", String anon_fun, doc)inspeclist.By default,
parserecognizes two unit options,-helpand--help, which will print to standard outputusage_msgand the list of options, and exit the program. You can override this behaviour by specifying your own-helpand--helpoptions inspeclist.
val parse_dynamic : (key * spec * doc) list Stdlib.ref -> anon_fun -> usage_msg -> unitSame as
Arg.parse, except that thespeclistargument is a reference and may be updated during the parsing. A typical use for this feature is to parse command lines of the form:- command subcommand
optionswhere the list of options depends on the value of the subcommand argument.
- since
- 4.01.0
- command subcommand
val parse_argv : ?current:int Stdlib.ref -> string array -> (key * spec * doc) list -> anon_fun -> usage_msg -> unitArg.parse_argv ~current args speclist anon_fun usage_msgparses the arrayargsas if it were the command line. It uses and updates the value of~current(if given), orArg.current. You must set it before callingparse_argv. The initial value ofcurrentis the index of the program name (argument 0) in the array. If an error occurs,Arg.parse_argvraisesArg.Bad with the error message as argument. If option-helpor--helpis given,Arg.parse_argvraisesArg.Help with the help message as argument.
val parse_argv_dynamic : ?current:int Stdlib.ref -> string array -> (key * spec * doc) list Stdlib.ref -> anon_fun -> string -> unitSame as
Arg.parse_argv, except that thespeclistargument is a reference and may be updated during the parsing. SeeArg.parse_dynamic.- since
- 4.01.0
val parse_and_expand_argv_dynamic : int Stdlib.ref -> string array Stdlib.ref -> (key * spec * doc) list Stdlib.ref -> anon_fun -> string -> unitSame as
Arg.parse_argv_dynamic, except that theargvargument is a reference and may be updated during the parsing ofExpandarguments. SeeArg.parse_argv_dynamic.- since
- 4.05.0
val parse_expand : (key * spec * doc) list -> anon_fun -> usage_msg -> unitSame as
Arg.parse, except that theExpandarguments are allowed and thecurrentreference is not updated.- since
- 4.05.0
exceptionBad of stringFunctions in
specoranon_funcan raiseArg.Badwith an error message to reject invalid arguments.Arg.Badis also raised byArg.parse_argvin case of an error.
val usage : (key * spec * doc) list -> usage_msg -> unitArg.usage speclist usage_msgprints to standard error an error message that includes the list of valid options. This is the same message thatArg.parseprints in case of error.speclistandusage_msgare the same as forArg.parse.
val usage_string : (key * spec * doc) list -> usage_msg -> stringReturns the message that would have been printed by
Arg.usage, if provided with the same parameters.
val align : ?limit:int -> (key * spec * doc) list -> (key * spec * doc) listAlign the documentation strings by inserting spaces at the first alignment separator (tab or, if tab is not found, space), according to the length of the keyword. Use a alignment separator as the first character in a doc string if you want to align the whole string. The doc strings corresponding to
Symbolarguments are aligned on the next line.- parameter limit
options with keyword and message longer than
limitwill not be used to compute the alignment.
val current : int Stdlib.refPosition (in
Sys.argv) of the argument being processed. You can change this value, e.g. to forceArg.parseto skip some arguments.Arg.parseuses the initial value ofArg.currentas the index of argument 0 (the program name) and starts parsing arguments at the next element.
val read_arg : string -> string arrayArg.read_arg filereads newline-terminated command line arguments from filefile.- since
- 4.05.0
val read_arg0 : string -> string arrayIdentical to
Arg.read_argbut assumes null character terminated command line arguments.- since
- 4.05.0
val write_arg : string -> string array -> unitArg.write_arg file argswrites the argumentsargsnewline-terminated into the filefile. If the any of the arguments inargscontains a newline, useArg.write_arg0instead.- since
- 4.05.0
val write_arg0 : string -> string array -> unitIdentical to
Arg.write_argbut uses the null character for terminator instead of newline.- since
- 4.05.0