Util: Return the result of the option parsing

This commit is contained in:
Riyyi
2021-09-05 22:56:34 +02:00
parent e813ab0f73
commit 04482fb10d
+9 -3
View File
@@ -202,6 +202,8 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
bool ArgParser::parse(int argc, const char* argv[]) bool ArgParser::parse(int argc, const char* argv[])
{ {
bool result = true;
// Get program name // Get program name
m_name = argv[0] + std::string_view(argv[0]).find_last_of('/') + 1; m_name = argv[0] + std::string_view(argv[0]).find_last_of('/') + 1;
@@ -223,12 +225,16 @@ bool ArgParser::parse(int argc, const char* argv[])
// Long Option // Long Option
if (argument[0] == '-' && argument[1] == '-') { if (argument[0] == '-' && argument[1] == '-') {
argument = argument.substr(argument.find_first_not_of('-')); argument = argument.substr(argument.find_first_not_of('-'));
parseLongOption(argument, next); if (!parseLongOption(argument, next)) {
result = false;
}
} }
// Short Option // Short Option
else if (argument[0] == '-') { else if (argument[0] == '-') {
argument = argument.substr(argument.find_first_not_of('-')); argument = argument.substr(argument.find_first_not_of('-'));
parseShortOption(argument, next); if (!parseShortOption(argument, next)) {
result = false;
}
} }
// Argument // Argument
else { else {
@@ -236,7 +242,7 @@ bool ArgParser::parse(int argc, const char* argv[])
} }
} }
return true; return result;
} }
void ArgParser::addOption(Option&& option) void ArgParser::addOption(Option&& option)