package env_config

  1. Overview
  2. Docs

Source file configuration_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
open! Core
open! Async

module type S = sig
  (** Some configuration that a program wants *)
  type t [@@deriving of_sexp]

  (** The environment variable used to retrieve configuration overrides *)
  val environment_variable : string

  (** What to display when the environment variable is malformed, in addition
      to some helpful information *)
  val documentation : string

  (** Allow extra fields to be present in the configuration sexp deserializer.
      Most users will want this to be true, as it is unlikely the configuration
      will always be the same type, and most types are not versioned. *)
  val allow_extra_fields : bool
end

module type Overridable = sig
  include S

  (** A mechanism for instructing a different configuration than the default
      be loaded by providing a different environment value than a [t].

      This is used, for example, to modify a particular part of a [t] without
      having to specify all of it.
  *)
  module Environment_override : sig
    type t [@@deriving of_sexp]
  end

  (** The environment requested that the config be determined by
      [Environment_override]. The default is provided to this function. *)
  val from_override : default_config:t Or_error.t -> Environment_override.t -> t
end

(** The default configuration is loaded from a file on disk. *)
module Load_from_disk = struct
  (** The default path, and loading function are computed synchronously *)
  module type Blocking = sig
    type t

    include S with type t := t

    (** The default configuration *)
    val default_path : unit -> string

    (** How to load a configuration from disk. This will be used in conjunction
        with [default_path] if no override is provided. *)
    val load_from_disk : path:string -> t
  end

  module type Blocking_overridable = sig
    include Blocking
    include Overridable with type t := t
  end

  (** The default path, and loading function are computed asynchronously *)
  module type Async = sig
    type t

    include S with type t := t

    (** The default configuration *)
    val default_path : unit -> string Deferred.t

    (** How to load a configuration from disk. This will be used in conjunction
        with [default_path] if no override is provided. *)
    val load_from_disk : path:string -> t Deferred.t
  end

  module type Async_overridable = sig
    include Async
    include Overridable with type t := t
  end
end

(** The default configuration is computed, or embedded in the library *)
module Embedded_in_library = struct
  (** The default configuration is computed synchronously *)
  module type Blocking = sig
    type t

    include S with type t := t

    (** Compute the default configuration *)
    val default : unit -> t
  end

  module type Blocking_overridable = sig
    include Blocking
    include Overridable with type t := t
  end

  (** The default configuration is computed asynchronously *)
  module type Async = sig
    type t

    include S with type t := t

    (** Compute the default configuration *)
    val default : unit -> t Deferred.t
  end

  module type Async_overridable = sig
    include Async
    include Overridable with type t := t
  end
end