forked from jorgecasar/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowtestgen_config.ml
85 lines (76 loc) · 2.12 KB
/
flowtestgen_config.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
(**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
module Config_utils = Flowtestgen_utils.Config;;
open Printf;;
(* Config module *)
type t = {
(* the number of programs we generate *)
num_prog : int;
(* Whether we log to the console *)
log_to_console : bool;
(* Whether we want to type check using Flow *)
type_check : bool;
(* Whether we want to generate programs randomly *)
random : bool;
(* which engine to use *)
engine : string
}
(* Default config value *)
let default_config : t = {
num_prog = 10;
log_to_console = false;
type_check = false;
random = true;
engine = "base";
};;
(* Default filename for the config file *)
let config_filename = "flowtestgen.json";;
let string_of_config (conf : t) : string =
let plist = Config_utils.(
[("num_prog", Int conf.num_prog);
("type_check", Bool conf.type_check);
("random", Bool conf.random);
("engine", Str conf.engine);
("log_to_console", Bool conf.log_to_console)]) in
Config_utils.string_of_config plist;;
let load_config () : t =
if not (Sys.file_exists config_filename) then begin
printf "No config file detected. Creating one with default values...\n";
let out = open_out config_filename in
let config_str = string_of_config default_config in
fprintf out "%s\n" config_str;
close_out out;
end;
let conf = Config_utils.load_json_config config_filename in
let dc = default_config in {
num_prog =
(Config_utils.get_int
~default:dc.num_prog
conf
"num_prog");
engine =
(Config_utils.get_str
~default:dc.engine
conf
"engine");
type_check =
(Config_utils.get_bool
~default:dc.type_check
conf
"type_check");
random =
(Config_utils.get_bool
~default:dc.random
conf
"random");
log_to_console =
(Config_utils.get_bool
~default:dc.log_to_console
conf
"log_to_console")
}
let config = load_config ();;