You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
7 years ago
|
(*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
7 years ago
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*)
|
||
7 years ago
|
|
||
6 years ago
|
(** Configuration options from config file *)
|
||
7 years ago
|
|
||
6 years ago
|
let config_file_env_var = "SLEDGE_CONFIG"
|
||
|
let exe_relative_config_file_path = "config"
|
||
6 years ago
|
|
||
6 years ago
|
let config_file =
|
||
|
match Core.Sys.getenv config_file_env_var with
|
||
|
| Some file -> file
|
||
|
| None ->
|
||
|
Filename.concat
|
||
|
(Filename.dirname Caml.Sys.executable_name)
|
||
|
exe_relative_config_file_path
|
||
7 years ago
|
|
||
6 years ago
|
let contents =
|
||
|
try Yojson.Basic.from_file config_file
|
||
|
with Sys_error _ ->
|
||
|
warn
|
||
|
"could not read config file %s@\n\
|
||
|
The path to the config file can be overridden by the %s environment \
|
||
|
variable."
|
||
|
config_file config_file_env_var () ;
|
||
|
`Assoc []
|
||
|
|
||
|
let find key = Yojson.Basic.Util.(to_string_option (member key contents))
|
||
|
|
||
6 years ago
|
let find_list key =
|
||
|
Yojson.Basic.Util.(filter_string (to_list (member key contents)))
|
||
|
|
||
6 years ago
|
let find_exn key =
|
||
|
match find key with
|
||
|
| Some data -> data
|
||
6 years ago
|
| None -> fail "%s not specified in config file %s" key config_file ()
|