| 1 |
(**************************************************************************) |
| 2 |
(* *) |
| 3 |
(* Copyright 2015-2016 OCamlPro *) |
| 4 |
(* *) |
| 5 |
(* All rights reserved. This file is distributed under the terms of the *) |
| 6 |
(* GNU Lesser General Public License version 2.1, with the special *) |
| 7 |
(* exception on linking described in the file LICENSE. *) |
| 8 |
(* *) |
| 9 |
(**************************************************************************) |
| 10 |
|
| 11 |
module E = struct |
| 12 |
|
| 13 |
type OpamStd.Config.E.t += |
| 14 |
| ALLPARENS of bool option |
| 15 |
| SKIPVERSIONCHECKS of bool option |
| 16 |
| STRICT of bool option |
| 17 |
|
| 18 |
open OpamStd.Config.E |
| 19 |
let allparens = value (function ALLPARENS b -> b | _ -> None) |
| 20 |
let skipversionchecks = value (function SKIPVERSIONCHECKS b -> b | _ -> None) |
| 21 |
let strict = value (function STRICT b -> b | _ -> None) |
| 22 |
|
| 23 |
end |
| 24 |
|
| 25 |
type t = { |
| 26 |
strict: bool; |
| 27 |
skip_version_checks: bool; |
| 28 |
all_parens: bool; |
| 29 |
} |
| 30 |
|
| 31 |
type 'a options_fun = |
| 32 |
?strict:bool -> |
| 33 |
?skip_version_checks:bool -> |
| 34 |
?all_parens:bool -> |
| 35 |
'a |
| 36 |
|
| 37 |
let default = { |
| 38 |
strict = false; |
| 39 |
skip_version_checks = false; |
| 40 |
all_parens = false; |
| 41 |
} |
| 42 |
|
| 43 |
let setk k t |
| 44 |
?strict |
| 45 |
?skip_version_checks |
| 46 |
?all_parens |
| 47 |
= |
| 48 |
let (+) x opt = match opt with Some x -> x | None -> x in |
| 49 |
k { |
| 50 |
strict = t.strict + strict; |
| 51 |
skip_version_checks = t.skip_version_checks + skip_version_checks; |
| 52 |
all_parens = t.all_parens + all_parens; |
| 53 |
} |
| 54 |
|
| 55 |
let set t = setk (fun x () -> x) t |
| 56 |
|
| 57 |
(* Global configuration reference *) |
| 58 |
|
| 59 |
let r = ref default |
| 60 |
|
| 61 |
let update ?noop:_ = setk (fun cfg () -> r := cfg) !r |
| 62 |
|
| 63 |
let initk k = |
| 64 |
setk (setk (fun c -> r := c; k)) !r |
| 65 |
?strict:(E.strict ()) |
| 66 |
?skip_version_checks:(E.skipversionchecks ()) |
| 67 |
?all_parens:(E.allparens ()) |
| 68 |
|
| 69 |
let init ?noop:_ = initk (fun () -> ()) |