1
0
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:
Henry Fredrick Schreiner 2017-03-09 09:41:10 -05:00
parent bdf3993d09
commit af79da5d84
2 changed files with 20 additions and 3 deletions

View File

@ -895,7 +895,8 @@ protected:
for(const Option_p& opt : options_) { for(const Option_p& opt : options_) {
// Eat options, one by one, until done // Eat options, one by one, until done
if ( opt->get_positional() if ( opt->get_positional()
&& opt->count() < opt->get_expected() && (opt->count() < opt->get_expected()
|| opt->get_expected() < 0)
) { ) {
opt->add_result(positional); opt->add_result(positional);

View File

@ -248,7 +248,7 @@ TEST_F(TApp, Positionals) {
TEST_F(TApp, ForcedPositional) { TEST_F(TApp, ForcedPositional) {
std::vector<std::string> posit; std::vector<std::string> posit;
auto one = app.add_flag("--one"); 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"}; args = {"--one", "two", "three"};
run(); run();
@ -260,7 +260,6 @@ TEST_F(TApp, ForcedPositional) {
args = {"--", "--one", "two", "three"}; args = {"--", "--one", "two", "three"};
std::vector<std::string> answers2 = {"--one", "two", "three"}; std::vector<std::string> answers2 = {"--one", "two", "three"};
pos->expected(3);
run(); run();
EXPECT_FALSE(one->count()); EXPECT_FALSE(one->count());
@ -285,6 +284,23 @@ TEST_F(TApp, MixedPositionals) {
EXPECT_EQ("thing2", positional_string); 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) { TEST_F(TApp, Reset) {
app.add_flag("--simple"); app.add_flag("--simple");