Browse Source

Util: Fix parsing for exit on first error setting

master
Riyyi 3 years ago
parent
commit
f021cf0e15
  1. 19
      src/util/argparser.cpp

19
src/util/argparser.cpp

@ -76,8 +76,7 @@ bool ArgParser::parseShortOption(std::string_view option, std::string_view next)
return result; return result;
} }
} }
else if (foundOption->requiresArgument == Required::No) {
if (foundOption->requiresArgument == Required::No) {
// FIXME: Figure out why providing a nullptr breaks the lambda here. // FIXME: Figure out why providing a nullptr breaks the lambda here.
result = foundOption->acceptValue(""); result = foundOption->acceptValue("");
} }
@ -144,24 +143,16 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
}); });
if (foundOption == m_options.cend()) { if (foundOption == m_options.cend()) {
foundOption->error = Error::UnrecognizedOption;
printOptionError(name.data(), Error::UnrecognizedOption); printOptionError(name.data(), Error::UnrecognizedOption);
result = false; result = false;
if (m_exitOnFirstError) {
return result;
}
} }
else if (argumentProvided) {
if (argumentProvided) {
if (foundOption->requiresArgument == Required::No) { if (foundOption->requiresArgument == Required::No) {
foundOption->error = Error::DoesntAllowArgument; foundOption->error = Error::DoesntAllowArgument;
printOptionError(name.data(), Error::DoesntAllowArgument); printOptionError(name.data(), Error::DoesntAllowArgument);
result = false; result = false;
if (m_exitOnFirstError) {
return result;
}
} }
else if (foundOption->requiresArgument == Required::Yes) { else if (foundOption->requiresArgument == Required::Yes) {
result = foundOption->acceptValue(value.data()); result = foundOption->acceptValue(value.data());
@ -176,9 +167,6 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
printOptionError(name.data(), Error::RequiresArgument); printOptionError(name.data(), Error::RequiresArgument);
result = false; result = false;
if (m_exitOnFirstError) {
return result;
}
} }
else { else {
result = foundOption->acceptValue(next.data()); result = foundOption->acceptValue(next.data());
@ -190,9 +178,6 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next)
printOptionError(name.data(), Error::RequiresArgument); printOptionError(name.data(), Error::RequiresArgument);
result = false; result = false;
if (m_exitOnFirstError) {
return result;
}
} }
else { else {
// FIXME: Figure out why providing a nullptr breaks the lambda here. // FIXME: Figure out why providing a nullptr breaks the lambda here.

Loading…
Cancel
Save