43#include <unordered_map>
61 [[maybe_unused]]
const std::regex
SWITCH_REGEX(R
"(^([-+])([a-zA-Z]*)$)");
85 std::unordered_map<std::string, bool>
switches;
136 void addSwitch(
const std::string& name,
bool defaultValue,
const std::string& description =
"");
148 const std::string& description =
"",
149 bool requiresNumber =
true);
157 void addKeywordArg(
const std::string& name,
int defaultValue,
const std::string& description =
"");
167 [[nodiscard]] std::string
getPosArg(
size_t index)
const;
196 void printUsage(
const std::string& reason =
"")
const;
void parseArgs()
This function is used to parse the command-line arguments and store them in the appropriate class mem...
Definition argParse.cpp:170
void addPosArg(char name, const std::string &description="", bool requiresNumber=true)
This function is used to add a positional argument to the class.
Definition argParse.cpp:53
bool getSwitch(const std::string &name)
This function is used to get the value of a switch.
Definition argParse.cpp:149
std::map< std::string, std::string > keywordArgDescriptions
This map is used to store the descriptions of all keyword arguments specified.
Definition argParse.hpp:102
int getKeywordArgument(const std::string &name)
This function is used to get the value of a keyword argument.
Definition argParse.cpp:141
std::vector< bool > posArgIsNumber
This map stores whether the positional arguments are required to be numbers.
Definition argParse.hpp:94
std::string getPosArg(size_t index) const
This function is used to get the value of a positional argument.
Definition argParse.cpp:133
std::vector< std::string > posArgs
This vector is used to store the values of all positional arguments specified.
Definition argParse.hpp:90
std::vector< std::string > argv
This stores the arguments passed to the program.
Definition argParse.hpp:108
void addSwitch(const std::string &name, bool defaultValue, const std::string &description="")
This function is used to add a switch to the class.
Definition argParse.cpp:41
std::map< std::string, std::string > switchDescriptions
This map is used to store the descriptions of all switches specified.
Definition argParse.hpp:87
std::unordered_map< std::string, int > keywordArgs
This map is used to store the values of all keyword arguments specified. Keys are keyword argument na...
Definition argParse.hpp:100
std::unordered_map< std::string, bool > switches
This map is used to store the information of all switches specified. Keys are switch names,...
Definition argParse.hpp:85
std::map< char, std::string > posArgDescriptions
This map is used to store the descriptions of all positional arguments specified.
Definition argParse.hpp:92
ProgramArgs(int _argc, const char **argv)
The constructor of the ProgramArgs class, which copies the arguments passed to the program to the cla...
Definition argParse.cpp:158
void addKeywordArg(const std::string &name, int defaultValue, const std::string &description="")
This function is used to add a keyword argument to the class.
Definition argParse.cpp:47
void printUsage(const std::string &reason="") const
This function is used to print the possible command-line arguments. Usually called when the user spec...
Definition argParse.cpp:59
std::string programName
This stores the name of the program.
Definition argParse.hpp:111
int argc
This stores the number of arguments passed to the program.
Definition argParse.hpp:105
The namespace containing utility functions for the Steppable library.
Definition argParse.cpp:40
const std::regex SWITCH_REGEX(R"(^([-+])([a-zA-Z]*)$)")
This is the correct format of a switch.
const std::regex KEYWORD_ARG_REGEX(R"(^-([a-zA-Z]*):(-?[0-9]+)$)")
This is the correct format of a keyword argument.
std::vector< std::string > PosArgs
This is the type of the positional arguments. It is equivalent to a vector of string_views.
Definition argParse.hpp:53