|
|
@ -31,19 +31,19 @@ void ArgParser::printError(const char* parameter, Error error, bool longName) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (error == Error::InvalidOption) { |
|
|
|
if (error == Error::OptionInvalid) { |
|
|
|
printf("%s: invalid option -- '%s'\n", m_name, parameter); |
|
|
|
printf("%s: invalid option -- '%s'\n", m_name, parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (error == Error::UnrecognizedOption) { |
|
|
|
else if (error == Error::OptionUnrecognized) { |
|
|
|
printf("%s: unrecognized option -- '%s'\n", m_name, parameter); |
|
|
|
printf("%s: unrecognized option -- '%s'\n", m_name, parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (error == Error::DoesntAllowArgument) { |
|
|
|
else if (error == Error::OptionDoesntAllowArgument) { |
|
|
|
printf("%s: option '--%s' doesn't allow an argument\n", m_name, parameter); |
|
|
|
printf("%s: option '--%s' doesn't allow an argument\n", m_name, parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (error == Error::ExtraOperand) { |
|
|
|
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::RequiresArgument) { |
|
|
|
else if (error == Error::OptionRequiresArgument) { |
|
|
|
if (longName) { |
|
|
|
if (longName) { |
|
|
|
printf("%s: option '--%s' requires an argument", m_name, parameter); |
|
|
|
printf("%s: option '--%s' requires an argument", m_name, parameter); |
|
|
|
} |
|
|
|
} |
|
|
@ -51,7 +51,7 @@ void ArgParser::printError(const char* parameter, Error error, bool longName) |
|
|
|
printf("%s: option requires an argument -- '%s'\n", m_name, parameter); |
|
|
|
printf("%s: option requires an argument -- '%s'\n", m_name, parameter); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (error == Error::InvalidArgumentType) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ bool ArgParser::parseShortOption(std::string_view option, std::string_view next) |
|
|
|
|
|
|
|
|
|
|
|
// Option does not exist
|
|
|
|
// Option does not exist
|
|
|
|
if (foundOption == m_options.cend()) { |
|
|
|
if (foundOption == m_options.cend()) { |
|
|
|
printError(c, Error::InvalidOption); |
|
|
|
printError(c, Error::OptionInvalid); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
if (m_exitOnFirstError) { |
|
|
|
if (m_exitOnFirstError) { |
|
|
@ -92,8 +92,8 @@ bool ArgParser::parseShortOption(std::string_view option, std::string_view next) |
|
|
|
else if (foundOption->requiresArgument == Required::Yes) { |
|
|
|
else if (foundOption->requiresArgument == Required::Yes) { |
|
|
|
value = option.substr(i + 1); |
|
|
|
value = option.substr(i + 1); |
|
|
|
if (value.empty() && next.empty()) { |
|
|
|
if (value.empty() && next.empty()) { |
|
|
|
foundOption->error = Error::RequiresArgument; |
|
|
|
foundOption->error = Error::OptionRequiresArgument; |
|
|
|
printError(c, Error::RequiresArgument); |
|
|
|
printError(c, Error::OptionRequiresArgument); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
if (m_exitOnFirstError) { |
|
|
|
if (m_exitOnFirstError) { |
|
|
@ -104,8 +104,8 @@ bool ArgParser::parseShortOption(std::string_view option, std::string_view next) |
|
|
|
result = foundOption->acceptValue(value.data()); |
|
|
|
result = foundOption->acceptValue(value.data()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (next[0] == '-') { |
|
|
|
else if (next[0] == '-') { |
|
|
|
foundOption->error = Error::RequiresArgument; |
|
|
|
foundOption->error = Error::OptionRequiresArgument; |
|
|
|
printError(c, Error::RequiresArgument); |
|
|
|
printError(c, Error::OptionRequiresArgument); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
if (m_exitOnFirstError) { |
|
|
|
if (m_exitOnFirstError) { |
|
|
@ -152,14 +152,14 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (foundOption == m_options.cend()) { |
|
|
|
if (foundOption == m_options.cend()) { |
|
|
|
printError(name.data(), Error::UnrecognizedOption); |
|
|
|
printError(name.data(), Error::OptionUnrecognized); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (argumentProvided) { |
|
|
|
else if (argumentProvided) { |
|
|
|
if (foundOption->requiresArgument == Required::No) { |
|
|
|
if (foundOption->requiresArgument == Required::No) { |
|
|
|
foundOption->error = Error::DoesntAllowArgument; |
|
|
|
foundOption->error = Error::OptionDoesntAllowArgument; |
|
|
|
printError(name.data(), Error::DoesntAllowArgument); |
|
|
|
printError(name.data(), Error::OptionDoesntAllowArgument); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -172,8 +172,8 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next) |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!next.empty() && foundOption->requiresArgument == Required::Yes) { |
|
|
|
else if (!next.empty() && foundOption->requiresArgument == Required::Yes) { |
|
|
|
if (next[0] == '-') { |
|
|
|
if (next[0] == '-') { |
|
|
|
foundOption->error = Error::RequiresArgument; |
|
|
|
foundOption->error = Error::OptionRequiresArgument; |
|
|
|
printError(name.data(), Error::RequiresArgument); |
|
|
|
printError(name.data(), Error::OptionRequiresArgument); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -183,8 +183,8 @@ bool ArgParser::parseLongOption(std::string_view option, std::string_view next) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (foundOption->requiresArgument == Required::Yes) { |
|
|
|
else if (foundOption->requiresArgument == Required::Yes) { |
|
|
|
foundOption->error = Error::RequiresArgument; |
|
|
|
foundOption->error = Error::OptionRequiresArgument; |
|
|
|
printError(name.data(), Error::RequiresArgument); |
|
|
|
printError(name.data(), Error::OptionRequiresArgument); |
|
|
|
|
|
|
|
|
|
|
|
result = false; |
|
|
|
result = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -203,7 +203,7 @@ bool ArgParser::parseArgument(std::string_view argument) |
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
// Run out of argument handlers
|
|
|
|
// Run out of argument handlers
|
|
|
|
if (m_argumentIndex >= m_arguments.size()) { |
|
|
|
if (m_argumentIndex >= m_arguments.size()) { |
|
|
|
printError(argument.data(), Error::ExtraOperand); |
|
|
|
printError(argument.data(), Error::ArgumentExtraOperand); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -221,7 +221,7 @@ bool ArgParser::parseArgument(std::string_view argument) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
printError(argument.data(), Error::InvalidArgumentType); |
|
|
|
printError(argument.data(), Error::ArgumentInvalidType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|