|
|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cb::argparser::Argument::Argument(std::string content, cb::argparser::Type type) : content{std::move(content)}, type{type} {
|
|
|
|
|
if (type == Type::BOOL && this->content == "false") {
|
|
|
|
|
if (type == Type::BOOL_TYPE && this->content == "false") {
|
|
|
|
|
this->content = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -16,7 +16,7 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
|
|
|
|
|
throw std::runtime_error(error_message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode == Mode::POSITIONAL) {
|
|
|
|
|
if (mode == Mode::POSITIONAL_MODE) {
|
|
|
|
|
assert(short_name.empty() && "The name should be left empty if it's a positional argument!");
|
|
|
|
|
assert(name.empty() && "The name should be left empty if it's a positional argument!");
|
|
|
|
|
} else {
|
|
|
|
|
@ -31,7 +31,7 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
|
|
|
|
|
argument.description = std::move(description);
|
|
|
|
|
argument.default_value = std::move(default_value);
|
|
|
|
|
|
|
|
|
|
if (mode == Mode::POSITIONAL) {
|
|
|
|
|
if (mode == Mode::POSITIONAL_MODE) {
|
|
|
|
|
positional_arguments.push_back(argument);
|
|
|
|
|
} else {
|
|
|
|
|
arguments.push_back(argument);
|
|
|
|
|
@ -115,7 +115,7 @@ cb::argparser::ArgumentMap cb::argparser::ArgumentParser::parse_arguments(int ar
|
|
|
|
|
bool
|
|
|
|
|
cb::argparser::ArgumentParser::requiresAdditionalArgument(const cb::argparser::ParseArgument &parseArgument, int argc,
|
|
|
|
|
char *const *argv, int i) {
|
|
|
|
|
if (parseArgument.type != Type::BOOL) {
|
|
|
|
|
if (parseArgument.type != Type::BOOL_TYPE) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -132,7 +132,7 @@ cb::argparser::ArgumentParser::requiresAdditionalArgument(const cb::argparser::P
|
|
|
|
|
|
|
|
|
|
void cb::argparser::ArgumentParser::verify_required_arguments_present() const {
|
|
|
|
|
for (auto &&argument: arguments) {
|
|
|
|
|
if (argument.mode != Mode::REQUIRED) {
|
|
|
|
|
if (argument.mode != Mode::REQUIRED_MODE) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!argument.is_present) {
|
|
|
|
|
@ -162,7 +162,7 @@ void cb::argparser::ArgumentParser::consume_argument(cb::argparser::ArgumentMap
|
|
|
|
|
void cb::argparser::ArgumentParser::add_argument(const std::string &short_name, const std::string &name,
|
|
|
|
|
cb::argparser::Type type, std::string description, bool default_value,
|
|
|
|
|
cb::argparser::Mode mode) {
|
|
|
|
|
assert(type == Type::BOOL);
|
|
|
|
|
assert(type == Type::BOOL_TYPE);
|
|
|
|
|
std::string value = default_value ? "1" : "";
|
|
|
|
|
add_argument(short_name, name, type, std::move(description), value, mode);
|
|
|
|
|
}
|
|
|
|
|
@ -176,6 +176,6 @@ void cb::argparser::ArgumentParser::add_argument(const std::string &short_name,
|
|
|
|
|
void cb::argparser::ArgumentParser::add_argument(const std::string &short_name, const std::string &name,
|
|
|
|
|
cb::argparser::Type type, std::string description, int default_value,
|
|
|
|
|
cb::argparser::Mode mode) {
|
|
|
|
|
assert(type == Type::INTEGER);
|
|
|
|
|
assert(type == Type::INTEGER_TYPE);
|
|
|
|
|
add_argument(short_name, name, type, std::move(description), std::to_string(default_value), mode);
|
|
|
|
|
}
|
|
|
|
|
|