Skip to content

Commit

Permalink
Fix short options adding into unmatched
Browse files Browse the repository at this point in the history
Fixes #312.
  • Loading branch information
jarro2783 committed Oct 20, 2021
1 parent a150450 commit c74846a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/cxxopts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,7 @@ OptionParser::parse(int argc, const char* const* argv)
{
if (m_allow_unrecognised)
{
unmatched.push_back(std::string("-") + s[i]);
continue;
}
//error
Expand Down
3 changes: 2 additions & 1 deletion test/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ TEST_CASE("Unrecognised options", "[options]") {
"--long",
"-su",
"--another_unknown",
"-a",
});

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

Expand Down

0 comments on commit c74846a

Please sign in to comment.