Util: Add ArgParser missing argument error message
This commit is contained in:
@@ -59,6 +59,9 @@ void ArgParser::printError(const char* parameter, Error error, bool longName)
|
|||||||
else if (error == Error::ArgumentExtraOperand) {
|
else if (error == Error::ArgumentExtraOperand) {
|
||||||
printf("%s: extra operand '%s'\n", m_name, parameter);
|
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) {
|
else if (error == Error::ArgumentInvalidType) {
|
||||||
printf("%s: invalid argument type '%s'\n", m_name, parameter);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Figure out why providing a nullptr breaks the lambda here.
|
|
||||||
result = foundOption->acceptValue("");
|
result = foundOption->acceptValue("");
|
||||||
}
|
}
|
||||||
else if (foundOption->requiresArgument == Required::Yes) {
|
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);
|
Argument& currentArgument = m_arguments.at(m_argumentIndex);
|
||||||
if (currentArgument.minValues > currentArgument.addedValues) {
|
if (currentArgument.minValues > currentArgument.addedValues) {
|
||||||
result = false;
|
result = false;
|
||||||
// TODO: decide if and what to print here
|
printError(currentArgument.name ? currentArgument.name : "", Error::ArgumentRequired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public:
|
|||||||
OptionRequiresArgument,
|
OptionRequiresArgument,
|
||||||
OptionInvalidArgumentType,
|
OptionInvalidArgumentType,
|
||||||
ArgumentExtraOperand,
|
ArgumentExtraOperand,
|
||||||
|
ArgumentRequired,
|
||||||
ArgumentInvalidType,
|
ArgumentInvalidType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user