Util: Add ArgParser missing argument error message

This commit is contained in:
Riyyi
2021-09-13 19:54:59 +02:00
parent bb29919f02
commit 3efe74582f
2 changed files with 5 additions and 2 deletions
+4 -2
View File
@@ -59,6 +59,9 @@ void ArgParser::printError(const char* parameter, Error error, bool longName)
else if (error == Error::ArgumentExtraOperand) {
printf("%s: extra operand '%s'\n", m_name, parameter);
}
else if (error == Error::ArgumentRequired) {
printf("%s: missing required argument '%s'\n", m_name, parameter);
}
else if (error == Error::ArgumentInvalidType) {
printf("%s: invalid argument type '%s'\n", m_name, parameter);
}
@@ -179,7 +182,6 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
return false;
}
// FIXME: Figure out why providing a nullptr breaks the lambda here.
result = foundOption->acceptValue("");
}
else if (foundOption->requiresArgument == Required::Yes) {
@@ -312,7 +314,7 @@ bool ArgParser::parse(int argc, const char* argv[])
Argument& currentArgument = m_arguments.at(m_argumentIndex);
if (currentArgument.minValues > currentArgument.addedValues) {
result = false;
// TODO: decide if and what to print here
printError(currentArgument.name ? currentArgument.name : "", Error::ArgumentRequired);
}
}
+1
View File
@@ -30,6 +30,7 @@ public:
OptionRequiresArgument,
OptionInvalidArgumentType,
ArgumentExtraOperand,
ArgumentRequired,
ArgumentInvalidType,
};