Skip to content

Commit 8f9731c

Browse files
committed
engine: Read several options from environment variables
The following environment variables are checked: CLOE_SIMULATION_UUID="string" Corresponds to -u, --uuid option. CLOE_WRITE_OUTPUT=0|1 Corresponds to --write-output, --no-write-output flags. CLOE_REQUIRE_SUCCESS=0|1 Corresponds to --require-success, --no-require-success flags. CLOE_LOG_LEVEL=trace|debug|info|warn|error|critical Corresponds to -l, --level option. CLOE_STRICT_MODE=0|1 Corresponds to -t, --strict, --no-strict flags. CLOE_SECURE_MODE=0|1 Corresponds to -s, --secure, --no-secure flags. Note that a command line argument takes precedence over these environment variables.
1 parent f44eeb5 commit 8f9731c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

engine/src/main.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ int main(int argc, char** argv) {
8080
std::vector<std::string> run_files;
8181
auto run = app.add_subcommand("run", "Run a simulation with (merged) stack files.");
8282
run->add_option("-J,--json-indent", run_options.json_indent, "JSON indentation level");
83-
run->add_option("-u,--uuid", run_options.uuid, "Override simulation UUID");
83+
run->add_option("-u,--uuid", run_options.uuid, "Override simulation UUID")
84+
->envname("CLOE_SIMULATION_UUID");
8485
run->add_flag("--allow-empty", run_options.allow_empty, "Allow empty simulations");
85-
run->add_flag("!--no-write-output", run_options.write_output, "Do not write any output files");
86-
run->add_flag("!--no-progress", run_options.report_progress, "Do not report progress");
87-
run->add_flag("--require-success", run_options.require_success, "Require simulation success");
86+
run->add_flag("--write-output,!--no-write-output", run_options.write_output,
87+
"Do (not) write any output files")
88+
->envname("CLOE_WRITE_OUTPUT");
89+
run->add_flag("--progress,!--no-progress", run_options.report_progress,
90+
"Do (not) report progress");
91+
run->add_flag("--require-success,!--no-require-success", run_options.require_success,
92+
"Require simulation success")
93+
->envname("CLOE_REQUIRE_SUCCESS");
8894
run->add_option("files", run_files, "Files to merge into a single stackfile")->required();
8995

9096
// One of the above subcommands must be used.
@@ -93,7 +99,9 @@ int main(int argc, char** argv) {
9399
// Global Options:
94100
std::string log_level = "warn";
95101
app.set_help_all_flag("-H,--help-all", "Print all help messages and exit");
96-
app.add_option("-l,--level", log_level, "Default logging level");
102+
app.add_option("-l,--level", log_level,
103+
"Default logging level, one of [trace, debug, info, warn, error, critical]")
104+
->envname("CLOE_LOG_LEVEL");
97105

98106
// Stack Options:
99107
cloe::StackOptions stack_options;
@@ -117,10 +125,12 @@ int main(int argc, char** argv) {
117125
// The --strict flag here is useful for all our smoketests, since this is the
118126
// combination of flags we use for maximum reproducibility / isolation.
119127
// Note: This option also affects / overwrites options for the run subcommand!
120-
app.add_flag("-t,--strict", stack_options.strict_mode,
121-
"Forces flags: --no-system-plugins --no-system-confs --require-success");
122-
app.add_flag("-s,--secure", stack_options.secure_mode,
123-
"Forces flags: --strict --no-hooks --no-interpolate");
128+
app.add_flag("-t,--strict,!--no-strict", stack_options.strict_mode,
129+
"Forces flags: --no-system-plugins --no-system-confs --require-success")
130+
->envname("CLOE_STRICT_MODE");
131+
app.add_flag("-s,--secure,!--no-secure", stack_options.secure_mode,
132+
"Forces flags: --strict --no-hooks --no-interpolate")
133+
->envname("CLOE_SECURE_MODE");
124134

125135
// ----------------------------------------------------------------------- //
126136

0 commit comments

Comments
 (0)