mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 05:53:52 +00:00
Fix unlimited positionals
This commit is contained in:
parent
bdf3993d09
commit
af79da5d84
@ -895,7 +895,8 @@ protected:
|
||||
for(const Option_p& opt : options_) {
|
||||
// Eat options, one by one, until done
|
||||
if ( opt->get_positional()
|
||||
&& opt->count() < opt->get_expected()
|
||||
&& (opt->count() < opt->get_expected()
|
||||
|| opt->get_expected() < 0)
|
||||
) {
|
||||
|
||||
opt->add_result(positional);
|
||||
|
@ -248,7 +248,7 @@ TEST_F(TApp, Positionals) {
|
||||
TEST_F(TApp, ForcedPositional) {
|
||||
std::vector<std::string> posit;
|
||||
auto one = app.add_flag("--one");
|
||||
auto pos = app.add_option("posit", posit)->expected(2); // Expected -1 broken?
|
||||
app.add_option("posit", posit);
|
||||
|
||||
args = {"--one", "two", "three"};
|
||||
run();
|
||||
@ -260,7 +260,6 @@ TEST_F(TApp, ForcedPositional) {
|
||||
|
||||
args = {"--", "--one", "two", "three"};
|
||||
std::vector<std::string> answers2 = {"--one", "two", "three"};
|
||||
pos->expected(3);
|
||||
run();
|
||||
|
||||
EXPECT_FALSE(one->count());
|
||||
@ -285,6 +284,23 @@ TEST_F(TApp, MixedPositionals) {
|
||||
EXPECT_EQ("thing2", positional_string);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BigPositional) {
|
||||
std::vector<std::string> vec;
|
||||
app.add_option("pos", vec);
|
||||
|
||||
args = {"one"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(args, vec);
|
||||
|
||||
app.reset();
|
||||
|
||||
args = {"one", "two"};
|
||||
run();
|
||||
|
||||
EXPECT_EQ(args, vec);
|
||||
}
|
||||
|
||||
TEST_F(TApp, Reset) {
|
||||
|
||||
app.add_flag("--simple");
|
||||
|
Loading…
x
Reference in New Issue
Block a user