Fix short options adding into unmatched

Fixes #312.
This commit is contained in:
Jarryd Beck 2021-10-21 08:06:22 +11:00
parent a150450486
commit c74846a891
2 changed files with 3 additions and 1 deletions

View File

@ -2243,6 +2243,7 @@ OptionParser::parse(int argc, const char* const* argv)
{ {
if (m_allow_unrecognised) if (m_allow_unrecognised)
{ {
unmatched.push_back(std::string("-") + s[i]);
continue; continue;
} }
//error //error

View File

@ -656,6 +656,7 @@ TEST_CASE("Unrecognised options", "[options]") {
"--long", "--long",
"-su", "-su",
"--another_unknown", "--another_unknown",
"-a",
}); });
auto** argv = av.argv(); auto** argv = av.argv();
@ -669,7 +670,7 @@ TEST_CASE("Unrecognised options", "[options]") {
options.allow_unrecognised_options(); options.allow_unrecognised_options();
auto result = options.parse(argc, argv); auto result = options.parse(argc, argv);
auto& unmatched = result.unmatched(); auto& unmatched = result.unmatched();
CHECK((unmatched == std::vector<std::string>{"--unknown", "--another_unknown"})); CHECK((unmatched == std::vector<std::string>{"--unknown", "-u", "--another_unknown", "-a"}));
} }
} }