Util: Support for optional arguments in ArgParser
This commit is contained in:
+20
-11
@@ -191,20 +191,29 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
|
|||||||
|
|
||||||
bool ArgParser::parseArgument(std::string_view argument)
|
bool ArgParser::parseArgument(std::string_view argument)
|
||||||
{
|
{
|
||||||
// No handler for argument
|
bool result = true;
|
||||||
if (m_argumentIndex >= m_arguments.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Argument& currentArgument = m_arguments.at(m_argumentIndex);
|
for (;;) {
|
||||||
bool result = currentArgument.acceptValue(argument.data());
|
// Run out of argument handlers
|
||||||
|
if (m_argumentIndex >= m_arguments.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (result) {
|
Argument& currentArgument = m_arguments.at(m_argumentIndex);
|
||||||
currentArgument.addedValues++;
|
result = currentArgument.acceptValue(argument.data());
|
||||||
}
|
|
||||||
|
|
||||||
if (currentArgument.addedValues >= currentArgument.maxValues) {
|
if (result) {
|
||||||
m_argumentIndex++;
|
currentArgument.addedValues++;
|
||||||
|
if (currentArgument.addedValues >= currentArgument.maxValues) {
|
||||||
|
m_argumentIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (currentArgument.minValues == 0) {
|
||||||
|
m_argumentIndex++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user