package batteries
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=b691e5870f876c6e590d6aa51b4c5457
sha512=3b0643ff337cd70da8c4b77887d212e82d043a7163fca36588be12186bc86bbcf0d56b13349325f12eabb96c846204c88560786342f50af7bf4e20b9480d3964
doc/batteries.unthreaded/BatOptParse/Opt/index.html
Module BatOptParse.OptSource
This module contains the basic functions and types for defining new option types and accessing the values of options.
Exceptions
No_value gets raised by OptParse.Opt.get when an option value is not available.
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.
When an option wants to display a usage message, this exception may be raised. It can never "escape" the scope of a OptParse.OptParser.parse call and the user should therefore not attempt to catch it.
Types
type 'a t = {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.
Option value retrieval
Find out if the option has a value (either by default or from the command line).
Option creation
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 option has no default value.
val callback_option :
string ->
(string -> 'a) ->
(exn -> string -> string) ->
('a -> unit) ->
unit tMake 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.