12#include <gemc/guts/gutsConventions.h>
98 if (yamlConf !=
nullptr) {
99 if (yamlConf->is_open()) { yamlConf->close(); }
121 void defineSwitch(
const std::string& name,
const std::string& description,
bool default_status =
false);
148 void defineOption(
const std::string& name,
const std::string& description,
const std::vector<GVariable>& gvars,
149 const std::string& help);
202 [[nodiscard]]
bool getSwitch(
const std::string& tag)
const;
221 [[nodiscard]]
inline YAML::Node
getOptionNode(
const std::string& tag)
const {
223 std::cerr <<
"Option " << tag <<
" does not exist. Exiting." << std::endl;
226 const auto& option_value = getOptionIterator(tag)->value;
227 if (!option_value || option_value.size() == 0) {
return YAML::Node{}; }
228 return option_value.begin()->second;
245 [[nodiscard]] YAML::Node
getOptionMapInNode(
const std::string& option_name,
const std::string& map_key)
const;
282 [[nodiscard]]
int getDebugFor(
const std::string& tag)
const;
296 [[nodiscard]]
const std::map<std::string, GSwitch>&
getSwitches()
const {
return switches; }
318 auto already = std::find_if(
320 [&opt](
const GOption& o) { return o.name == opt.name; });
333 auto same = std::find_if(
335 [&v](
const GVariable& existing) { return existing.name == v.name; });
352 std::string option_verbosity_name_desc = name +
" verbosity level or debug switch";
369 template <
typename T>
370 T
get_variable_in_option(
const YAML::Node& node,
const std::string& variable_name,
const T& default_value);
373 template <
typename T>
377 template <
typename T>
390 [[nodiscard]] std::vector<std::string>
getYamlFiles()
const {
return yaml_files; }
402 std::map<std::string, GSwitch> switches;
403 std::ofstream* yamlConf{};
404 std::string executableName;
405 std::string executableCallingDir;
407 std::string installDir;
408 std::vector<std::string> yaml_files;
410 std::vector<std::string> findYamls(
int argc,
char* argv[]);
411 void setOptionsValuesFromYamlFile(
const std::string& yaml);
412 void setOptionValuesFromCommandLineArgument(
const std::string& optionName,
const std::string& possibleYamlNode);
413 std::vector<GOption>::iterator getOptionIterator(
const std::string& name);
414 [[nodiscard]] std::vector<GOption>::const_iterator getOptionIterator(
const std::string& name)
const;
415 void printOptionOrSwitchHelp(
const std::string& tag)
const;
416 void printSearch(
const std::string& tag)
const;
417 void printHelp()
const;
418 void printWebHelp()
const;
419 void saveOptions()
const;
420 void print_version();
Stores one configuration option (scalar or structured), including schema defaults and current value.
Parses, stores, and exposes command-line options and YAML configuration values.
bool getSwitch(const std::string &tag) const
Retrieves the status of a switch.
const std::vector< GOption > & getOptions() const
Returns the list of defined options.
double getRequiredScalarDouble(const std::string &tag) const
Retrieves the required value of a scalar double option.
YAML::Node getOptionNode(const std::string &tag) const
Retrieves the YAML node for the specified option.
void addOptionTitle(const std::string &name)
GOptions(std::string name)
Constructor for creating verbosity/debug schema helpers.
void setOptionValueFromString(const std::string &optionName, const std::string &possibleYamlNode)
Updates an option value from a YAML-formatted string.
GOptions()
Default constructor.
void defineOption(const GVariable &gvar, const std::string &help)
Defines and adds a scalar option.
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.
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.
bool doesOptionExist(const std::string &tag) const
Checks if an option exists.
std::vector< std::string > getYamlFiles() const
Returns the list of YAML file paths detected on the command line.
void addGOptions(const GOptions &src)
Merges options and switches from another GOptions : into this one.
std::optional< std::string > getOptionalScalarString(const std::string &tag) const
Retrieves the optional value of a scalar string option.
std::optional< double > getOptionalScalarDouble(const std::string &tag) const
const std::map< std::string, GSwitch > & getSwitches() const
Returns the map of defined switches.
std::optional< T > get_optional_variable_in_option(const YAML::Node &node, const std::string &variable_name)
std::string getRequiredScalarString(const std::string &tag) const
Retrieves the required value of a scalar string option.
int getDebugFor(const std::string &tag) const
Retrieves the debug level for the specified tag.
std::optional< int > getOptionalScalarInt(const std::string &tag) const
int getVerbosityFor(const std::string &tag) const
Retrieves the verbosity level for the specified tag.
T get_required_variable_in_option(const YAML::Node &node, const std::string &variable_name)
void defineSwitch(const std::string &name, const std::string &description, bool default_status=false)
Defines and adds a command-line switch.
std::vector< GVariable > option_verbosity_names
Schema entries used to define the verbosity and debug structured options.
int getRequiredScalarInt(const std::string &tag) const
Retrieves the required value of a scalar integer option.
Definitions of GVariable : and GOption : used by GOptions : .
GOptions & operator+=(GOptions &original, const GOptions &optionsToAdd)
Overloaded operator to add options and switches from one GOptions : to another.
Definition of GSwitch : the boolean command-line switch type used by GOptions : .
constexpr int EC__NOOPTIONFOUND
Option/switch/key not found, or invalid command-line token.
Describes a schema entry: key name, default value, and user-facing description.