package ocf
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=cc0ce6cb4c4ba1d0d3e76ece6fbdf1cf
sha512=f8ee35def82ab0ab039ea7deb64f7dce64f35ad22f07177d610b4ed6f5ae243708db1a4332aa91c1da6638d6c3c09aea10a45d9870f3257d4e8324bacd5bbef4
doc/ocf/Ocf/index.html
Module OcfSource
Reading and writing configuration files in JSON syntax
To represent option names from root.
Errors
type error = | Json_error of string(*JSON could not be read or written
*)| Invalid_value of Yojson.Safe.t(*Unexpected JSON value
*)| Invalid_path of path(*Invalid path used (empty list)
*)| Path_conflict of path(*When adding an option, an option path cannot be the prefix of another one.
*)| Error_at_path of path * error(*Error while reading the option at the given path.
*)| Exn_at_path of path * exn(*Exception raised while reading the option at the given path
*)
Convenient functions to raise Error
Wrappers
A wrapper is a pair of functions to read and write values of some type from and to JSON.
Options and option groups
An option with a value of type 'a. When the option is found in a JSON code (see Reading options), the value is modified in place. Use get to retrieve the option value.
option wrapper v creates an option with initial value v and using the given wrapper to read and write from and to JSON.
get option returns the value of the given option.
set option value sets the value of the given option and calls the associated callback if any.
A group is used to group options and other groups. An `Open group is a group in which other options and groups can be added. Nothing can be added to a `Closed group.
add group path option adds the given option to group at path.
add_group group path g adds the group g to group at path.
as_group option creates a group from option, i.e. like if the given option had an empty access path. Useful for options created from a record wrapper using the ppx extension and that must be read as root element of a JSON file.
Convenient functions to create options
val json :
?doc:string ->
?cb:(Yojson.Safe.t -> unit) ->
Yojson.Safe.t ->
Yojson.Safe.t conf_optionval list :
?doc:string ->
?cb:('a list -> unit) ->
'a wrapper ->
'a list ->
'a list conf_optionval option_ :
?doc:string ->
?cb:('a option -> unit) ->
'a wrapper ->
'a option ->
'a option conf_optionval pair :
?doc:string ->
?cb:(('a * 'b) -> unit) ->
'a wrapper ->
'b wrapper ->
('a * 'b) ->
('a * 'b) conf_optionval triple :
?doc:string ->
?cb:(('a * 'b * 'c) -> unit) ->
'a wrapper ->
'b wrapper ->
'c wrapper ->
('a * 'b * 'c) ->
('a * 'b * 'c) conf_optionval string_map :
?doc:string ->
?cb:('map -> unit) ->
fold:
((string -> 'a -> Wrapper.assocs -> Wrapper.assocs) ->
'map ->
Wrapper.assocs ->
Wrapper.assocs) ->
add:(string -> 'a -> 'map -> 'map) ->
empty:'map ->
'a wrapper ->
'map ->
'map conf_optionSee Wrapper.string_map for parameters.
Reading options
Writing options
The following functions output the current state of the group, i.e. the options it contains, with their current value.
The with_doc parameter indicates whether to output doc associated to options. Default is true.
Building command line arguments
to_arg option key build a command line option description to use with the Arg module. If doc is not provided, then the description string of the option is used, if there is one; else the doc string is empty (preventing the option to appear in the list of options, see Arg module documentation). key is the option name, like "-n".