Skip to content

Commit

Permalink
refactor(config): add alias for enable/disable (#7394)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Mar 23, 2023
1 parent 19a1760 commit ece4161
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/dune_config/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ let all = ref []

let register t = all := E t :: !all

module Toggle = struct
type t =
[ `Enabled
| `Disabled
]

let of_string = function
| "enabled" -> Ok `Enabled
| "disabled" -> Ok `Disabled
| _ -> Error (sprintf "only %S and %S are allowed" "enabled" "disabled")
end

let init values =
if !initialized then Code_error.raise "Config.init: already initialized" [];
let all =
Expand Down Expand Up @@ -56,14 +68,7 @@ let init values =

let global_lock =
let t =
{ name = "global_lock"
; of_string =
(function
| "enabled" -> Ok `Enabled
| "disabled" -> Ok `Disabled
| _ -> Error (sprintf "only %S and %S are allowed" "enabled" "disabled"))
; value = `Enabled
}
{ name = "global_lock"; of_string = Toggle.of_string; value = `Enabled }
in
register t;
t
9 changes: 8 additions & 1 deletion src/dune_config/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ open Stdune
is the configuration option's name in uppercase *)
type 'a t

module Toggle : sig
type t =
[ `Enabled
| `Disabled
]
end

(** [get t] return the value of the configuration for [t] *)
val get : 'a t -> 'a

(** should dune acquire the global lock before building *)
val global_lock : [ `Enabled | `Disabled ] t
val global_lock : Toggle.t t

(** Before any configuration value is accessed, this function must be called
with all the configuration values from the relevant config file
Expand Down

0 comments on commit ece4161

Please sign in to comment.