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; }
174 auto already = std::find_if(
176 [&opt](
const GOption& o) { return o.name == opt.name; });
189 auto same = std::find_if(
191 [&v](
const GVariable& existing) { return existing.name == v.name; });
202 std::string option_verbosity_name_desc = name +
" verbosity level or debug switch";
214 template <
typename T>
215 T
get_variable_in_option(
const YAML::Node& node,
const std::string& variable_name,
const T& default_value);
221 [[nodiscard]] std::vector<std::string>
getYamlFiles()
const {
return yaml_files; }
232 std::map<std::string, GSwitch> switches;
233 std::ofstream* yamlConf{};
234 std::string executableName;
235 std::string executableCallingDir;
236 std::string installDir;
237 std::vector<std::string> yaml_files;
245 std::vector<std::string> findYamls(
int argc,
char* argv[]);
251 void setOptionsValuesFromYamlFile(
const std::string& yaml);
258 void setOptionValuesFromCommandLineArgument(
const std::string& optionName,
const std::string& possibleYamlNode);
265 std::vector<GOption>::iterator getOptionIterator(
const std::string& name);
272 [[nodiscard]] std::vector<GOption>::const_iterator getOptionIterator(
const std::string& name)
const;
278 void printOptionOrSwitchHelp(
const std::string& tag)
const;
283 void printHelp()
const;
288 void printWebHelp()
const;
293 void saveOptions()
const;
298 void print_version();
Represents a configurable option with a name, value(s), description, and help text.
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.
const std::vector< GOption > & getOptions() const
Returns the list of defined options.
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.
double getScalarDouble(const std::string &tag) const
Retrieves the value of a scalar double option.
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.
void addGOptions(const GOptions &src)
Adds options from another GOptions object.
const std::map< std::string, GSwitch > & getSwitches() const
Returns the map of defined switches.
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.