mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Merge pull request #360 from rouault/too_few_arguments
Add argument name after 'Too few arguments' error
This commit is contained in:
commit
9893754f67
@ -997,7 +997,8 @@ public:
|
|||||||
std::bind(is_optional, std::placeholders::_1, m_prefix_chars));
|
std::bind(is_optional, std::placeholders::_1, m_prefix_chars));
|
||||||
dist = static_cast<std::size_t>(std::distance(start, end));
|
dist = static_cast<std::size_t>(std::distance(start, end));
|
||||||
if (dist < num_args_min) {
|
if (dist < num_args_min) {
|
||||||
throw std::runtime_error("Too few arguments");
|
throw std::runtime_error("Too few arguments for '" +
|
||||||
|
std::string(m_used_name) + "'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,15 @@ TEST_CASE("Missing argument" * test_suite("parse_args")) {
|
|||||||
std::runtime_error);
|
std::runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Missing argument, not last" * test_suite("parse_args")) {
|
||||||
|
argparse::ArgumentParser program("test");
|
||||||
|
program.add_argument("--config").nargs(1);
|
||||||
|
program.add_argument("--foo");
|
||||||
|
REQUIRE_THROWS_WITH_AS(program.parse_args({"test", "--config", "--foo"}),
|
||||||
|
"Too few arguments for '--config'.",
|
||||||
|
std::runtime_error);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a string argument with value" * test_suite("parse_args")) {
|
TEST_CASE("Parse a string argument with value" * test_suite("parse_args")) {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--config");
|
program.add_argument("--config");
|
||||||
|
Loading…
Reference in New Issue
Block a user