7 #include "gutsConventions.h"
55 if (yamlConf !=
nullptr) {
56 if (yamlConf->is_open()) { yamlConf->close(); }
67 void defineSwitch(
const std::string& name,
const std::string& description);
83 void defineOption(
const std::string& name,
const std::string& description,
const std::vector<GVariable>& gvars,
84 const std::string& help);
91 [[nodiscard]]
int getScalarInt(
const std::string& tag)
const;
106 [[nodiscard]] std::string
getScalarString(
const std::string& tag)
const;
113 [[nodiscard]]
bool getSwitch(
const std::string& tag)
const;
121 [[nodiscard]]
inline YAML::Node
getOptionNode(
const std::string& tag)
const {
123 std::cerr <<
"Option " << tag <<
" does not exist. Exiting." << std::endl;
126 return getOptionIterator(tag)->value.begin()->second;
135 [[nodiscard]] YAML::Node
getOptionMapInNode(
const std::string& option_name,
const std::string& map_key)
const;
152 [[nodiscard]]
int getDebugFor(
const std::string& tag)
const;
164 [[nodiscard]]
const std::map<std::string, GSwitch>&
getSwitches()
const {
return switches; }
172 for (
const auto& sw : goptions_to_add.
getSwitches()) { switches.insert(sw); }
180 std::string option_verbosity_name_desc = name +
" verbosity level or debug switch";
192 template <
typename T>
193 T
get_variable_in_option(
const YAML::Node& node,
const std::string& variable_name,
const T& default_value);
199 [[nodiscard]] std::vector<std::string>
getYamlFiles()
const {
return yaml_files; }
210 std::map<std::string, GSwitch> switches;
211 std::ofstream* yamlConf{};
212 std::string executableName;
213 std::string executableCallingDir;
214 std::vector<std::string> yaml_files;
222 std::vector<std::string> findYamls(
int argc,
char* argv[]);
228 void setOptionsValuesFromYamlFile(
const std::string& yaml);
235 void setOptionValuesFromCommandLineArgument(
const std::string& optionName,
const std::string& possibleYamlNode);
242 std::vector<GOption>::iterator getOptionIterator(
const std::string& name);
249 [[nodiscard]] std::vector<GOption>::const_iterator getOptionIterator(
const std::string& name)
const;
255 void printOptionOrSwitchHelp(
const std::string& tag)
const;
260 void printHelp()
const;
265 void printWebHelp()
const;
270 void saveOptions()
const;
275 void print_version();
The GOptions class manages command-line options and switches.
std::string option_verbosity_name
std::string getScalarString(const std::string &tag) const
Retrieves the value of a scalar string option.
bool getSwitch(const std::string &tag) const
Retrieves the status of a switch.
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 verbosity and debug options.
void defineSwitch(const std::string &name, const std::string &description)
Defines and adds a command–line switch.
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 option’s value from within a YAML node.
T get_variable_in_option(const YAML::Node &node, const std::string &variable_name, const T &default_value)
Retrieves a variable from a YAML node within an option.
const std::vector< GOption > & getOptions() const
Returns the list of defined options.
const std::map< std::string, GSwitch > & getSwitches() const
Returns the map of defined switches.
double getScalarDouble(const std::string &tag) const
Retrieves the value of a scalar double option.
void addGOptions(const GOptions &goptions_to_add)
Adds options from another GOptions object.
bool doesOptionExist(const std::string &tag) const
Checks if the specified option exists.
int getScalarInt(const std::string &tag) const
Retrieves the value of a scalar integer option.
std::vector< std::string > getYamlFiles() const
Retrieves the list of YAML file paths.
int getDebugFor(const std::string &tag) const
Retrieves the debug level for the specified tag.
int getVerbosityFor(const std::string &tag) const
Retrieves the verbosity level for the specified tag.
std::vector< GVariable > option_verbosity_names
#define EC__NOOPTIONFOUND
GOptions & operator+=(GOptions &original, const GOptions &optionsToAdd)
Overloaded operator to add options and switches from one GOptions object to another.
Encapsulates a variable with a name, value, and description.