goptions
Loading...
Searching...
No Matches
goptions.cc
Go to the documentation of this file.
1
14// goptions
15#include "goptions.h"
16#include "goptionsConventions.h"
17#include "gversion.h"
18
19// gemc
20#include "gutilities.h"
21
22// c++
23#include <iostream>
24#include <cstring>
25#include <cctype>
26#include <cstdlib>
27
28using namespace std;
29
30// See goptions.h for full constructor API documentation.
31/*
32 * Parsing precedence implemented here:
33 * 1. YAML file(s), applied in argv order
34 * 2. Command-line tokens override YAML values
35 *
36 * Notes:
37 * - "help <option>" is treated as an immediate action and exits after printing.
38 * - Dot-notation routes structured updates to the owning option via GOption::set_sub_option_value().
39 */
40GOptions::GOptions(int argc, char* argv[], const GOptions& user_defined_options) {
41 executableName = gutilities::getFileFromPath(argv[0]);
42 executableCallingDir = gutilities::getDirFromPath(argv[0]);
43 installDir = gutilities::gemc_root();
44 cout << endl;
45
46 // Add user-defined options.
47 addGOptions(user_defined_options);
48
49 // switches for all everyone
50 defineSwitch("gui", "run with the graphical user interface (Qt window)");
51 defineSwitch("i", "drop into the interactive Geant4 terminal session (non-GUI mode)");
53 GVariable("conf_yaml", "saved_configuration", "infix for the YAML file that records the resolved options"),
54 "On exit the resolved configuration is written to <executable>.<conf_yaml>.yaml,\n"
55 "so the default value produces, for example, gemc.saved_configuration.yaml.\n \n"
56 "Example: -conf_yaml=run12 -> saves to gemc.run12.yaml\n \n");
57
58 // add test timeout for the tests
59 defineOption(GVariable("tt", 500, "GUI test timeout (ms)"),
60 "Milliseconds a GUI-based test waits before it auto-closes, so the module\n"
61 "example/test programs can run unattended in CI.\n \n"
62 "Example: -tt=1000\n \n");
63
64 // version is a special option, not settable by the user
65 // it is set by the gversion.h file
66 // we add it here so it can be saved to the yaml file
67 vector<GVariable> version = {
68 {"release", gversion, "release version number"},
69 {"release_date", grelease_date, "release date"},
70 {"Reference", greference, "article reference"},
71 {"Homepage", gweb, "homepage"},
72 {"Author", gauthor, "author"}
73 };
74 defineOption(GVERSION_STRING, "version information", version, "Version information. Not settable by user.");
75
76 // verbosity option: convention used across modules consuming verbosity levels
77 string help = "Levels: \n \n";
78 help += " - 0: (default) = shush\n";
79 help += " - 1: log detailed information\n";
80 help += " - 2: log extra detailed information\n \n";
81 help += "Each key names a class or module; run 'help verbosity' to list the available keys.\n \n";
82 help += "Example (one key): -verbosity.gemc=1\n";
83 help += "Example (several keys): -verbosity=\"[{gemc: 1}, {<another_key>: 2}]\"\n \n";
84 help += "Equivalent YAML:\n";
85 help += " verbosity:\n";
86 help += " - gemc: 1\n";
87 help += " - <another_key>: 2\n \n";
88 defineOption("verbosity", "Sets the log verbosity for various classes", option_verbosity_names, help);
89
90 // debug option: boolean or integer, depending on consumer expectations
91 help = "Debug information Types: \n \n";
92 help += " - false: (default): do not print debug information\n";
93 help += " - true: print debug information\n\n";
94 help += "Each key names a class or module; run 'help debug' to list the available keys.\n \n";
95 help += "Example (on/off): -debug.gemc=true\n";
96 help += "Example (several keys): -debug=\"[{gemc: true}, {<another_key>: 1}]\"\n \n";
97 help += "Equivalent YAML:\n";
98 help += " debug:\n";
99 help += " - gemc: true\n \n";
100 defineOption("debug", "Sets the debug level for various classes", option_verbosity_names, help);
101
102 // Process help/version command-line arguments.
103 // These are handled early and exit immediately (they do not proceed to parse YAML/options).
104 for (int i = 1; i < argc; i++) {
105 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--h") == 0 ||
106 strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0) {
107 printHelp();
108 }
109 else if (strcmp(argv[i], "-hweb") == 0) {
110 printWebHelp();
111 }
112 else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--v") == 0 ||
113 strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
114 print_version();
115 exit(EXIT_SUCCESS);
116 }
117 else if (strcmp(argv[i], "help") == 0) {
118 // "gemc help <topic>" shows topic help; bare "gemc help" shows the general help index.
119 if (i + 1 < argc) { printOptionOrSwitchHelp(argv[i + 1]); }
120 else { printHelp(); }
121 exit(EXIT_SUCCESS);
122 }
123 else if (strcmp(argv[i], "search") == 0) {
124 // "gemc search <value>" lists options/switches whose name or description contains <value>.
125 if (i + 1 < argc) { printSearch(argv[i + 1]); }
126 else { printHelp(); }
127 exit(EXIT_SUCCESS);
128 }
129 }
130
131 // finds and parse the yaml files
132 // YAML file tokens are treated as inputs, not as "invalid command-line arguments".
133 yaml_files = findYamls(argc, argv);
134 for (auto& yaml_file : yaml_files) {
135 cout << " Parsing " << yaml_file << endl;
136 setOptionsValuesFromYamlFile(yaml_file);
137 }
138
139 // Parse command-line arguments (supports both standard YAML–style and dot–notation).
140 for (int i = 1; i < argc; i++) {
141 string candidate = argv[i];
142 if (candidate.empty()) continue;
143
144 // Skip YAML file tokens: they were already handled above.
145 if (find(yaml_files.begin(), yaml_files.end(), candidate) != yaml_files.end()) continue;
146
147 if (candidate[0] == '-') {
148 string argStr = candidate.substr(1);
149 size_t eqPos = argStr.find('=');
150
151 if (eqPos != string::npos) {
152 string keyPart = argStr.substr(0, eqPos);
153 string valuePart = argStr.substr(eqPos + 1);
154
155 // Switch with an explicit boolean value: -gui=false / -gui=true. This gives the
156 // CLI a way to turn a switch off, honoring the documented CLI-over-YAML precedence.
157 if (switches.find(keyPart) != switches.end()) {
158 if (valuePart == "true" || valuePart == "1") { switches[keyPart].turnOn(); }
159 else if (valuePart == "false" || valuePart == "0") { switches[keyPart].turnOff(); }
160 else {
161 cerr << "The switch " << keyPart << " accepts only true/false." << endl;
162 exit(EC__NOOPTIONFOUND);
163 }
164 continue;
165 }
166
167 // Strip outer quotes if present (e.g., -gstreamer="[...]")
168 if (!valuePart.empty() && valuePart.front() == '"' && valuePart.back() == '"') {
169 valuePart = valuePart.substr(1, valuePart.length() - 2);
170 }
171
172 // Dot-notation targets a subkey in a structured option (e.g., verbosity.gemc).
173 size_t dotPos = keyPart.find('.');
174 if (dotPos != string::npos) {
175 string mainOption = keyPart.substr(0, dotPos);
176 string subOption = keyPart.substr(dotPos + 1);
177
178 if (doesOptionExist(mainOption)) {
179 auto it = getOptionIterator(mainOption);
180 it->set_sub_option_value(subOption, valuePart);
181 }
182 else {
183 cerr << "The option " << mainOption << " is not known to this system." << endl;
184 exit(EC__NOOPTIONFOUND);
185 }
186 }
187 else {
188 // Standard option syntax: -name=value
189 if (doesOptionExist(keyPart)) {
190 setOptionValuesFromCommandLineArgument(keyPart, valuePart);
191 }
192 else {
193 cerr << "The option " << keyPart << " is not known to this system." << endl;
194 exit(EC__NOOPTIONFOUND);
195 }
196 }
197 }
198 else {
199 // Treat as a switch: -gui, -i, etc.
200 const string& possibleSwitch = argStr;
201 if (switches.find(possibleSwitch) != switches.end()) {
202 switches[possibleSwitch].turnOn();
203 }
204 else {
205 cerr << "The switch " << possibleSwitch << " is not known to this system." << endl;
206 exit(EC__NOOPTIONFOUND);
207 }
208 }
209 }
210 else {
211 cerr << "The command-line argument \"" << candidate << "\" is not valid." << endl;
212 exit(EC__NOOPTIONFOUND);
213 }
214 }
215
216 // Always print version information.
217 print_version();
218
219 // Save the final configuration to a YAML file.
220 string yamlConf_filename = executableName + "." + getScalarString("conf_yaml") + ".yaml";
221 cout << " Saving options to " << yamlConf_filename << endl << endl;
222 yamlConf = new std::ofstream(yamlConf_filename);
223 saveOptions();
224}
225
226// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
227void GOptions::defineSwitch(const std::string& name, const std::string& description) {
228 if (switches.find(name) == switches.end()) {
229 switches[name] = GSwitch(description);
230 }
231 else {
232 std::cerr << FATALERRORL << "The " << YELLOWHHL << name << RSTHHR
233 << " switch is already present." << std::endl;
235 }
236}
237
238// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
239void GOptions::defineOption(const GVariable& gvar, const std::string& help) {
240 if (doesOptionExist(gvar.name)) {
241 std::cerr << FATALERRORL << "The " << YELLOWHHL << gvar.name << RSTHHR
242 << " option is already present." << std::endl;
244 }
245 else {
246 goptions.emplace_back(gvar, help);
247 }
248}
249
250// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
251void GOptions::defineOption(const std::string& name, const std::string& description,
252 const std::vector<GVariable>& gvars,
253 const std::string& help) {
254 if (doesOptionExist(name)) {
255 std::cerr << FATALERRORL << "The " << YELLOWHHL << name << RSTHHR
256 << " option is already present." << std::endl;
258 }
259 else {
260 goptions.emplace_back(name, description, gvars, help);
261 }
262}
263
264// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
265int GOptions::getScalarInt(const std::string& tag) const {
266 auto it = getOptionIterator(tag);
267 if (it == goptions.end()) {
268 cerr << FATALERRORL << "The option " << YELLOWHHL << tag << RSTHHR
269 << " was not found." << endl;
270 exit(EC__NOOPTIONFOUND);
271 }
272 return it->value.begin()->second.as<int>();
273}
274
275// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
276double GOptions::getScalarDouble(const std::string& tag) const {
277 auto it = getOptionIterator(tag);
278 if (it == goptions.end()) {
279 cerr << FATALERRORL << "The option " << YELLOWHHL << tag << RSTHHR
280 << " was not found." << endl;
281 exit(EC__NOOPTIONFOUND);
282 }
283 return it->value.begin()->second.as<double>();
284}
285
286// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
287std::string GOptions::getScalarString(const std::string& tag) const {
288 auto it = getOptionIterator(tag);
289 if (it == goptions.end()) {
290 std::cerr << FATALERRORL << "The option " << YELLOWHHL << tag << RSTHHR
291 << " was not found." << std::endl;
292 std::exit(EC__NOOPTIONFOUND);
293 }
294 const YAML::Node node = it->value.begin()->second;
295 if (node.IsNull()) return "NULL"; // force the exact sentinel you prefer
296 return node.as<std::string>();
297}
298
299
300// Private method: see header. Kept undocumented here to avoid duplicate param docs.
301void GOptions::printOptionOrSwitchHelp(const std::string& tag) const {
302 auto switchIt = switches.find(tag);
303 if (switchIt != switches.end()) {
304 cout << KGRN << "-" << tag << RST << ": " << switchIt->second.getDescription() << endl << endl;
305 cout << TPOINTITEM << "Default value is " << (switchIt->second.getStatus() ? "on" : "off") << endl << endl;
306 exit(EXIT_SUCCESS);
307 }
308 for (const auto& goption : goptions) {
309 if (goption.name == tag) {
310 goption.printHelp(true);
311 exit(EXIT_SUCCESS);
312 }
313 }
314 cerr << FATALERRORL << "The " << YELLOWHHL << tag << RSTHHR
315 << " option is not known to this system." << endl;
316 exit(EC__NOOPTIONFOUND);
317}
318
319// Private method: see header. Kept undocumented here to avoid duplicate param docs.
320void GOptions::printSearch(const std::string& tag) const {
321 // Case-insensitive substring match against switch/option names and descriptions.
322 auto to_lower = [](string s) {
323 transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
324 return s;
325 };
326 const string needle = to_lower(tag);
327 auto matches = [&](const string& a, const string& b) {
328 return to_lower(a).find(needle) != string::npos || to_lower(b).find(needle) != string::npos;
329 };
330
331 long int fill_width = string(HELPFILLSPACE).size() + 1;
332 cout.fill('.');
333 cout << KGRN << KBOLD << " Options and switches matching \"" << tag << "\":" << RST << endl << endl;
334
335 bool found = false;
336 for (auto& s : switches) {
337 if (matches(s.first, s.second.getDescription())) {
338 found = true;
339 cout << KGRN << " " << left;
340 cout.width(fill_width);
341 cout << "-" + s.first + RST + " " << ": " << s.second.getDescription() << endl;
342 }
343 }
344 for (auto& option : goptions) {
345 if (option.name != GVERSION_STRING && matches(option.name, option.description)) {
346 found = true;
347 option.printHelp(false);
348 }
349 }
350 if (!found) { cout << TPOINTITEM << "no match found." << endl; }
351 cout << endl << " Use " << KGRN << "help <value>" << RST << " for the detailed help of a single option." << endl
352 << endl;
353}
354
355// Private method: see header. Kept undocumented here to avoid duplicate param docs.
356vector<string> GOptions::findYamls(int argc, char* argv[]) {
357 vector<string> yaml_files;
358 auto ends_with = [](const string& s, const string& suffix) {
359 return s.size() >= suffix.size() &&
360 s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
361 };
362 for (int i = 1; i < argc; i++) {
363 string arg = argv[i];
364 // Match a trailing .yaml/.yml extension, not any substring, so option values such as
365 // -prefix=run.yaml.bak are not mistaken for input files (and silently dropped).
366 if (ends_with(arg, ".yaml") || ends_with(arg, ".yml")) yaml_files.push_back(arg);
367 }
368 return yaml_files;
369}
370
371// checks if the option exists
372// Public API docs are in goptions.h; doxygen param docs are kept only there.
373bool GOptions::doesOptionExist(const std::string& tag) const {
374 // [&tag] ensures we're referencing the original tag passed to the function
375 return std::any_of(goptions.begin(), goptions.end(),
376 [&tag](const auto& option) {
377 return option.name == tag;
378 });
379}
380
381// Private method: behavior described in header and top-of-file overview.
382void GOptions::setOptionsValuesFromYamlFile(const std::string& yaml) {
383 YAML::Node config;
384 try {
385 config = YAML::LoadFile(yaml);
386 }
387 catch (YAML::BadFile& e) {
388 cerr << FATALERRORL << "Cannot open yaml file " << YELLOWHHL << yaml << RSTHHR
389 << ". Check the path and spelling." << endl;
391 }
392 catch (YAML::ParserException& e) {
393 cerr << FATALERRORL << "Error parsing " << YELLOWHHL << yaml << RSTHHR
394 << " yaml file." << endl;
395 cerr << e.what() << endl;
396 cerr << "Try validating the yaml file with an online yaml validator, e.g., https://www.yamllint.com" << endl;
398 }
399
400 for (auto it = config.begin(); it != config.end(); ++it) {
401 auto option_name = it->first.as<std::string>();
402 auto option_it = getOptionIterator(option_name);
403
404 // If it is not an option, it may still be a switch.
405 if (option_it == goptions.end()) {
406 if (switches.find(option_name) == switches.end()) {
407 cerr << FATALERRORL << "The option or switch " << YELLOWHHL << option_name << RSTHHR
408 << " is not known to this system." << endl;
409 exit(EC__NOOPTIONFOUND);
410 }
411 else {
412 switches[option_name].turnOn();
413 }
414 }
415 else {
416 YAML::NodeType::value type = it->second.Type();
417 switch (type) {
418 case YAML::NodeType::Scalar:
419 option_it->set_scalar_value(it->second.as<std::string>());
420 break;
421 case YAML::NodeType::Sequence:
422 option_it->set_value(it->second);
423 break;
424 case YAML::NodeType::Map:
425 option_it->set_value(it->second);
426 break;
427 default:
428 break;
429 }
430 }
431 }
432}
433
434// Private method: behavior described in header and top-of-file overview.
435void GOptions::setOptionValuesFromCommandLineArgument(const std::string& optionName,
436 const std::string& possibleYamlNode) {
437 YAML::Node node = YAML::Load(possibleYamlNode);
438 auto option_it = getOptionIterator(optionName);
439
440 if (node.Type() == YAML::NodeType::Scalar) {
441 option_it->set_scalar_value(possibleYamlNode);
442 }
443 else {
444 option_it->set_value(node);
445 }
446}
447
448void GOptions::setOptionValueFromString(const std::string& optionName,
449 const std::string& possibleYamlNode) {
450 setOptionValuesFromCommandLineArgument(optionName, possibleYamlNode);
451}
452
453// Private method (private API): do not \ref; use \c getOptionIterator() in docs if needed.
454std::vector<GOption>::iterator GOptions::getOptionIterator(const std::string& name) {
455 return std::find_if(goptions.begin(), goptions.end(),
456 [&name](GOption& option) { return option.name == name; });
457}
458
459// Private method (private API): do not \ref; use \c getOptionIterator() in docs if needed.
460std::vector<GOption>::const_iterator GOptions::getOptionIterator(const std::string& name) const {
461 return std::find_if(goptions.begin(), goptions.end(),
462 [&name](const GOption& option) { return option.name == name; });
463}
464
465// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
466bool GOptions::getSwitch(const std::string& tag) const {
467 auto it = switches.find(tag);
468 if (it != switches.end()) {
469 return it->second.getStatus();
470 }
471 else {
472 std::cerr << FATALERRORL << "The switch " << YELLOWHHL << tag << RSTHHR
473 << " was not found." << std::endl;
474 exit(EC__NOOPTIONFOUND);
475 }
476}
477
478// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
479YAML::Node GOptions::getOptionMapInNode(const string& option_name, const string& map_key) const {
480 auto sequence_node = getOptionNode(option_name);
481
482 for (auto seq_item : sequence_node) {
483 for (auto map_item = seq_item.begin(); map_item != seq_item.end(); ++map_item) {
484 if (map_item->first.as<string>() == map_key) {
485 return map_item->second;
486 }
487 }
488 }
489
490 cerr << FATALERRORL << "The key " << YELLOWHHL << map_key << RSTHHR
491 << " was not found in " << YELLOWHHL << option_name << RSTHHR << endl;
492 exit(EC__NOOPTIONFOUND);
493}
494
495// Template documentation lives in the header to avoid duplicate \param blocks.
496template <typename T>
497T GOptions::get_variable_in_option(const YAML::Node& node, const std::string& variable_name, const T& default_value) {
498 if (node[variable_name]) {
499 return node[variable_name].as<T>();
500 }
501 return default_value;
502}
503
504// Explicit template instantiations.
505template int GOptions::get_variable_in_option<int>(const YAML::Node& node, const std::string& variable_name,
506 const int& default_value);
507template double GOptions::get_variable_in_option<double>(const YAML::Node& node, const std::string& variable_name,
508 const double& default_value);
509template string GOptions::get_variable_in_option<string>(const YAML::Node& node, const std::string& variable_name,
510 const string& default_value);
511template bool GOptions::get_variable_in_option<bool>(const YAML::Node& node, const std::string& variable_name,
512 const bool& default_value);
513
514// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
515int GOptions::getVerbosityFor(const std::string& tag) const {
516 YAML::Node verbosity_node = getOptionNode("verbosity");
517 for (auto v : verbosity_node) {
518 if (v.begin()->first.as<string>() == tag) {
519 return v.begin()->second.as<int>();
520 }
521 }
522
523 // not found. error
524 std::cerr << KRED << " Invalid verbosity or debug requested: " << tag << RST << std::endl;
526}
527
528// Implementation note: public API docs are in goptions.h (avoid duplicate \param blocks).
529int GOptions::getDebugFor(const std::string& tag) const {
530 YAML::Node debug_node = getOptionNode("debug");
531 for (auto d : debug_node) {
532 if (d.begin()->first.as<string>() == tag) {
533 YAML::Node valNode = d.begin()->second;
534 if (valNode.IsScalar()) {
535 auto s = valNode.as<string>();
536 if (s == "true") return 1;
537 if (s == "false") return 0;
538 }
539 try {
540 return valNode.as<int>();
541 }
542 catch (const YAML::BadConversion&) {
543 std::cerr << "Invalid debug value for " << tag << std::endl;
545 }
546 }
547 }
548 // not found. error
549 std::cerr << KRED << " Invalid verbosity or debug requested: " << tag << RST << std::endl;
551}
552
553// Private method: no Doxygen block here to avoid duplicate \param docs.
554void GOptions::printHelp() const {
555 long int fill_width = string(HELPFILLSPACE).size() + 1;
556 cout.fill('.');
557 cout << KGRN << KBOLD << " " << executableName << RST << " [options] [yaml files]" << endl << endl;
558 cout << " Switches: " << endl << endl;
559 for (auto& s : switches) {
560 string help = "-" + s.first + RST + " ";
561 cout << KGRN << " " << left;
562 cout.width(fill_width);
563 cout << help;
564 cout << ": " << s.second.getDescription() << endl;
565 }
566 cout << endl;
567 cout << " Options: " << endl << endl;
568 for (auto& option : goptions) {
569 option.printHelp(false);
570 }
571 cout << endl;
572 cout << endl << " Help / Search / Introspection: " << endl << endl;
573 vector<string> helps = {
574 string("-h, --h, -help, --help") + RST,
575 string("print this help and exit"),
576 string("-hweb") + RST,
577 string("print this help in web format and exit"),
578 string("-v, --v, -version, --version") + RST,
579 string("print the version and exit\n"),
580 string("help <value>") + RST,
581 string("print detailed help for option <value> and exit"),
582 string("search <value>") + RST,
583 string("list all options/switches whose name or description contains <value> and exit\n")
584 };
585 unsigned half_help = helps.size() / 2;
586 for (unsigned i = 0; i < half_help; i++) {
587 cout << KGRN << " " << left;
588 cout.width(fill_width);
589 cout << helps[i * 2] << ": " << helps[i * 2 + 1] << endl;
590 }
591 cout << endl;
592 cout << " Note: command line options overwrite YAML file(s)." << endl << endl;
594}
595
596// Private method: no Doxygen block here to avoid duplicate \param docs.
597void GOptions::printWebHelp() const {
599}
600
601// Private method: no Doxygen block here to avoid duplicate \param docs.
602void GOptions::saveOptions() const {
603 for (auto& s : switches) {
604 string status = s.second.getStatus() ? "true" : "false";
605 *yamlConf << s.first + ": " + status << "," << endl;
606 }
607 for (const auto& option : goptions) {
608 option.saveOption(yamlConf);
609 }
610 yamlConf->close();
611}
612
613// Private method: no Doxygen block here to avoid duplicate \param docs.
614void GOptions::print_version() {
615 string asterisks = "*******************************************************************";
616 cout << endl << asterisks << endl;
617 cout << " " << KGRN << KBOLD << executableName << RST << " version: " << KGRN << gversion << RST << endl;
618 cout << " Called from: " << KGRN << executableCallingDir << RST << endl;
619 cout << " Install: " << KGRN << installDir << "/bin" << RST << endl; //
620 cout << " Released on: " << KGRN << grelease_date << RST << endl;
621
622 // Report the plugin search path when one was provided, either through the
623 // -plugin_path option (or a plugin_path: YAML key) or the GEMC_PLUGIN_PATH
624 // environment variable.
625 string plugin_path = doesOptionExist("plugin_path") ? getScalarString("plugin_path") : "";
626 if (plugin_path == "NULL") plugin_path = "";
627 const char* plugin_env = std::getenv("GEMC_PLUGIN_PATH");
628 if (!plugin_path.empty() || (plugin_env != nullptr && plugin_env[0] != '\0')) {
629 string combined = plugin_path;
630 if (plugin_env != nullptr && plugin_env[0] != '\0') {
631 if (!combined.empty()) combined += ':';
633 }
634 cout << " Plugin path: " << KGRN << combined << RST << endl;
635 }
636
637 cout << " GEMC Reference: " << KGRN << greference << RST << endl;
638 cout << " GEMC Homepage: " << KGRN << gweb << RST << endl;
639 cout << " Author: " << KGRN << gauthor << RST << endl << endl;
640 cout << asterisks << endl << endl;
641}
642
643// Operator documentation is provided in goptions.h; do not duplicate it here.
644GOptions& operator+=(GOptions& gopts, const GOptions& goptions_to_add) {
645 gopts.addGOptions(goptions_to_add);
646 return gopts;
647}
Stores one configuration option (scalar or structured), including schema defaults and current value.
Definition goption.h:105
Parses, stores, and exposes command-line options and YAML configuration values.
Definition goptions.h:46
bool getSwitch(const std::string &tag) const
Retrieves the status of a switch.
Definition goptions.cc:466
YAML::Node getOptionNode(const std::string &tag) const
Retrieves the YAML node for the specified option.
Definition goptions.h:206
void setOptionValueFromString(const std::string &optionName, const std::string &possibleYamlNode)
Updates an option value from a YAML-formatted string.
Definition goptions.cc:448
void defineSwitch(const std::string &name, const std::string &description)
Defines and adds a command-line switch.
Definition goptions.cc:227
std::string getScalarString(const std::string &tag) const
Retrieves the value of a scalar string option.
Definition goptions.cc:287
GOptions()
Default constructor.
Definition goptions.h:56
void defineOption(const GVariable &gvar, const std::string &help)
Defines and adds a scalar option.
Definition goptions.cc:239
YAML::Node getOptionMapInNode(const std::string &option_name, const std::string &map_key) const
Retrieves a map entry value from a structured option stored as a sequence of maps.
Definition goptions.cc:479
T get_variable_in_option(const YAML::Node &node, const std::string &variable_name, const T &default_value)
Retrieves a typed variable from a YAML node within an option.
Definition goptions.cc:497
double getScalarDouble(const std::string &tag) const
Retrieves the value of a scalar double option.
Definition goptions.cc:276
bool doesOptionExist(const std::string &tag) const
Checks if an option exists.
Definition goptions.cc:373
int getScalarInt(const std::string &tag) const
Retrieves the value of a scalar integer option.
Definition goptions.cc:265
void addGOptions(const GOptions &src)
Merges options and switches from another GOptions : into this one.
Definition goptions.h:298
int getDebugFor(const std::string &tag) const
Retrieves the debug level for the specified tag.
Definition goptions.cc:529
int getVerbosityFor(const std::string &tag) const
Retrieves the verbosity level for the specified tag.
Definition goptions.cc:515
std::vector< GVariable > option_verbosity_names
Schema entries used to define the verbosity and debug structured options.
Definition goptions.h:341
Represents a boolean command-line switch with a description and a status.
Definition gswitch.h:28
Conventions, constants, and error codes for the GOptions : / GOption : subsystem.
#define EC__BAD_CONVERSION
YAML value could not be converted to requested type.
#define EC__NOOPTIONFOUND
Option/switch/key not found, or invalid command-line token.
#define EC__YAML_PARSING_ERROR
YAML file failed to parse (syntax error or parser failure).
#define HELPFILLSPACE
Padding used when printing option/switch help.
#define EC__DEFINED_SWITCHALREADYPRESENT
Attempted to define a switch name more than once.
#define EC__DEFINED_OPTION_ALREADY_PRESENT
Attempted to define an option name more than once.
#define GVERSION_STRING
Reserved option tag used to store version information.
GOptions & operator+=(GOptions &gopts, const GOptions &goptions_to_add)
Overloaded operator to add options and switches from one GOptions : to another.
Definition goptions.cc:644
Public interface for GOptions : the YAML + command-line configuration manager.
#define RSTHHR
#define YELLOWHHL
#define KRED
#define KBOLD
#define KGRN
#define FATALERRORL
#define RST
#define TPOINTITEM
std::filesystem::path gemc_root()
string getDirFromPath(const std::string &path)
string getFileFromPath(const std::string &path)
Describes a schema entry: key name, default value, and user-facing description.
Definition goption.h:34
std::string name
Variable name (option name for scalar options, schema key name for structured options).
Definition goption.h:35