module Release_config:sig
..end
Sections are started by a section name enclosed in square brackets.
Keys and values are separated by an equals sign, and values can be
integers, floats, booleans, strings, regular expressions, log levels
or lists of one of those types, as defined by the Release_values.value
type.
Keys must be named starting with a letter and optionally followed by any character except whitespace characters, square brackets, equals signs or hash signs.
Integers values are represented by sequences of digits and floats are represented by sequences of digits separated by a dot character.
Strings are sequences of characters enclosed by double quotes, and newline characters inside strings are supported.
Regular expressions are enclosed by forward slash characters and support
the same constructs as the ones documented in OCaml's Str
module, but
the grouping constructs (
and )
and the alternative between expressions
construct |
don't need to be escaped by a backslash. Newlines can be
inserted in regular expressions for organization purposes and are ignored
along with any following whitespace characters.
Log levels are bare words matching the definitions in Lwt_log
, that is,
debug
, info
, notice
, warning
, error
and fatal
.
Finally, lists are sequences of the above types enclosed by square brackets and separated by commas.
In terms of code, configuration files are specified by the
Release_config.spec
type. This is simply a list of
Release_config.section
s, each containing lists of
Release_config.key
s. Keys are defined by their name, an optional
default value and a list of validations. If a key has no default value
and is absent from the configuration file, an error will be generated.
Validations are functions as defined by the
Release_config_values.validation
type. Many pre-defined validations
are available in the Release_config_validations
module.
type
t
typekey =
string * Release_config_values.value option *
Release_config_values.validation list
typesection =
[ `Global of key list
| `Section of string * key list ]
typespec =
section list
val parse : Lwt_io.file_name ->
spec ->
[ `Configuration of t | `Error of string ] Lwt.t
parse file spec
will try to parse file
and, if it is syntatically correct, validate it against the specification
given in spec
.val defaults : spec -> t
defaults spec
returns a configuration built from the default values
of spec
. This only makes sense if every key in the specification has
a default value.val get : t -> string -> string -> Release_config_values.value
get conf section key
returns the value of the parameter key
of
section section
in configuration conf
.val get_global : t -> string -> Release_config_values.value
get_global conf key
returns the value of the global parameter key
.