31 #ifndef HERMES_COMMON_ARG_PARSER_H
32 #define HERMES_COMMON_ARG_PARSER_H
72 explicit ArgParser(std::string bin =
"", std::string description =
"");
81 bool parse(
int argc,
const char **argv,
bool verbose_parsing =
false);
88 const std::string &description =
"",
89 bool is_required =
false);
96 T
get(
const std::string &name,
const T &default_value = {})
const {
97 const auto &it = m_.find(name);
98 if (it == m_.end() || !arguments_[it->second].given || arguments_[it->second].values.empty())
100 std::istringstream in(arguments_[it->second].values[0]);
111 std::vector<T>
getList(
const std::string &name,
const std::vector<T> &default_value = {})
const {
112 const auto &it = m_.find(name);
113 if (it == m_.end() || !arguments_[it->second].given || arguments_[it->second].values.empty())
114 return default_value;
118 std::vector<T> values;
119 for (
auto &value : s_values) {
120 std::istringstream in(value);
123 values.template emplace_back(t);
130 [[nodiscard]]
bool check(
const std::string &name)
const;
136 std::string description{};
137 std::vector<std::string> names{};
138 std::vector<std::string> values{};
139 bool required{
false};
142 std::map<std::string, u64> m_;
143 std::vector<Argument> arguments_;
145 std::string description_;
Command line argument parser.
Definition: arg_parser.h:64
void addArgument(const std::string &name, const std::string &description="", bool is_required=false)
Define program argument.
Definition: arg_parser.cpp:92
bool parse(int argc, const char **argv, bool verbose_parsing=false)
Parse program arguments.
Definition: arg_parser.cpp:41
ArgParser(std::string bin="", std::string description="")
Constructor.
Definition: arg_parser.cpp:38
T get(const std::string &name, const T &default_value={}) const
Get argument value.
Definition: arg_parser.h:96
std::vector< T > getList(const std::string &name, const std::vector< T > &default_value={}) const
Get argument value as list.
Definition: arg_parser.h:111
bool check(const std::string &name) const
Checks if an argument was given.
Definition: arg_parser.cpp:116
void printHelp() const
Output help into stdout.
Definition: arg_parser.cpp:101
static std::vector< std::string > split(const std::string &s, const std::string &delimiters=" ")
Splits a string into tokens separated by delimiters.
Definition: str.cpp:170