Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ class Argument {
(m_choices.has_value()) ? passed_options : m_num_args_range.get_max();
const auto num_args_min = m_num_args_range.get_min();
std::size_t dist = 0;
if (num_args_max == 0) {
if (m_num_args_range.get_max() == 0) {
if (!dry_run) {
m_values.emplace_back(m_implicit_value);
for(auto &action: m_actions) {
Expand Down
10 changes: 10 additions & 0 deletions test/test_choices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,13 @@ TEST_CASE("Parse multiple arguments that are not in range of allowed choices" *
"Invalid argument \"d\" - allowed options: {a, b, c}",
std::runtime_error);
}

TEST_CASE("Optional option with choices and nargs(1) appearing last accepts "
"empty argument" *
test_suite("choices")) {
argparse::ArgumentParser program("test");
program.add_argument("--color").choices("red", "green").nargs(1);

REQUIRE_THROWS_AS(program.parse_args({"test", "--color"}),
std::runtime_error);
}