Config_fileSourceThis module implements a mechanism to handle configuration files. A configuration file is defined as a set of variable = value lines, where value can be
int, string, bool…);variable = value lines between braces.The configuration file is automatically loaded and saved, and configuration parameters are manipulated inside the program as easily as references.
Object implementation by Jean-Baptiste Rouquier.
Skip this section on a first reading...
The type of Configuration Parameter, in short cp, freshly parsed from a configuration file, not yet wrapped in their proper type.
A type used to specialize polymorphics classes and define new classes. Predefined wrappers are provided.
An exception raised by Config_file.cp.set_raw when the argument doesn't have a suitable Config_file.Raw.cp type. The function explains the problem and flushes the output.
A Configuration Parameter, in short cp, i.e. a value we can store in and read from a configuration file.
type groupable_cp =
< get_name : string list
; get_short_name : string option
; get_help : string
; get_formatted : Format.formatter -> unit
; get_default_formatted : Format.formatter -> unit
; get_help_formatted : Format.formatter -> unit
; get_spec : Arg.spec
; reset : unit
; set_raw : Raw.cp -> unit >Unification over all possible 'a cp: contains the main methods of 'a cp except the methods using the type 'a. A group manipulates only groupable_cp for homogeneity.
Raised in case a name is already used. See Config_file.group.add.
An exception possibly raised if we want to check that every cp is defined in a configuration file. See Config_file.group.read.
A group of cps, that can be loaded and saved, or used to generate command line arguments.
The last three non-optional arguments are always name (of type string list), default_value and help (of type string).
name is the path to the cp: ["section";"subsection"; ...; "foo"]. It can consists of a single element but must not be empty.
short_name will be added a "-" and used in Config_file.group.command_line_args.
group, if provided, adds the freshly defined option to it (something like initializer group#add self).
help needs not contain newlines, it will be automatically truncated where needed. It is mandatory but can be "".
class 'a enumeration_cp : (string * 'a) list -> ?group:group -> string list -> ?short_name:string -> 'a ->
string -> 'a cpclass string2_cp : ?group:group -> string list -> ?short_name:string -> (string * string) ->
string -> [string, string] tuple2_cpclass filename_cp : ?group:group -> string list -> ?short_name:string -> string -> string ->
string_cpIf you have a type suit = Spades | Hearts | Diamond | Clubs, then
enumeration_wrappers
[
("spades", Spades);
("hearts", Hearts);
("diamond", Diamond);
("clubs", Clubs);
]will allow you to use cp of this type. For sum types with not only constant constructors, you will need to define your own cp class.
class 'a cp_custom_type : 'a wrappers -> ?group:group -> string list -> ?short_name:string -> 'a ->
string -> 'a cpTo define a new cp class, you just have to provide an implementation for the wrappers between your type foo and the type Raw.cp.
All the functions from the module Options are available, except:
prune_file: use group#write ?obsoletes:"foo.ml".smalllist_to_value, smalllist_option: use lists or tuples.get_class.class_hook: hooks are local to a cp. If you want hooks global to a class, define a new class that inherits from Config_file.cp_custom_type.set_simple_option, get_simple_option, simple_options, simple_args: use Config_file.group.write.set_option_hook: use Config_file.cp.add_hook.set_string_wrappers: define a new class with Config_file.cp_custom_type.The old configurations files are readable by this module.