mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
max, min on positional was not respected, specifically max positionals only filled up to min, and skipped over optional options. Fixes #1090 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
ecdcf633a5
commit
d2b331f02a
@ -1731,7 +1731,7 @@ CLI11_INLINE bool App::_parse_positional(std::vector<std::string> &args, bool ha
|
||||
for(const Option_p &opt : options_) {
|
||||
// Eat options, one by one, until done
|
||||
if(opt->get_positional() &&
|
||||
(static_cast<int>(opt->count()) < opt->get_items_expected_min() || opt->get_allow_extra_args())) {
|
||||
(static_cast<int>(opt->count()) < opt->get_items_expected_max() || opt->get_allow_extra_args())) {
|
||||
if(validate_positionals_) {
|
||||
std::string pos = positional;
|
||||
pos = opt->_validate(pos, 0);
|
||||
|
@ -1236,6 +1236,56 @@ TEST_CASE_METHOD(TApp, "RequiredOptsDoubleNeg", "[app]") {
|
||||
CHECK(std::vector<std::string>({"one", "two"}) == strs);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ExpectedRangeParam", "[app]") {
|
||||
|
||||
app.add_option("-s")->required()->expected(2, 4);
|
||||
|
||||
args = {"-s", "one"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
|
||||
args = {"-s", "one", "two"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"-s", "one", "two", "three"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"-s", "one", "two", "three", "four"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"-s", "one", "two", "three", "four", "five"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ExpectedRangePositional", "[app]") {
|
||||
|
||||
app.add_option("arg")->required()->expected(2, 4);
|
||||
|
||||
args = {"one"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
|
||||
args = {"one", "two"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"one", "two", "three"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"one", "two", "three", "four"};
|
||||
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"one", "two", "three", "four", "five"};
|
||||
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
}
|
||||
|
||||
// This makes sure unlimited option priority is
|
||||
// correct for space vs. no space #90
|
||||
TEST_CASE_METHOD(TApp, "PositionalNoSpace", "[app]") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user