From da841b9f69aa249b02442eb6bffae1b507995eee Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 22 Nov 2017 13:55:16 -0500 Subject: [PATCH] Restore humgry option prioritizing over allow_extras --- CHANGELOG.md | 2 +- include/CLI/App.hpp | 8 ++------ tests/AppTest.cpp | 10 ++++++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b057f8..b0d8a1e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ * Failure messages are now customizable, with a shorter default [#52](https://github.com/CLIUtils/CLI11/pull/52) * `require_subcommand` now offers a two-argument form and negative values on the one-argument form are more useful [#51](https://github.com/CLIUtils/CLI11/pull/51) * Subcommands no longer match after the max required number is obtained [#51](https://github.com/CLIUtils/CLI11/pull/51) -* Unlimited options no longer prioritize over extras or remaining/unlimited positionals [#51](https://github.com/CLIUtils/CLI11/pull/51) +* Unlimited options no longer prioritize over remaining/unlimited positionals [#51](https://github.com/CLIUtils/CLI11/pull/51) ## Version 1.2 diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 48ad02da..15b464e9 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -1392,9 +1392,7 @@ class App { bool already_ate_one = false; // Make sure we always eat one while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) { if(already_ate_one) { - // If allow extras is true, don't keep eating - if(get_allow_extras()) - break; + // We could break here for allow extras, but we don't // If any positionals remain, don't keep eating if(_count_remaining_positionals() > 0) @@ -1471,9 +1469,7 @@ class App { bool already_ate_one = false; // Make sure we always eat one while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) { if(already_ate_one) { - // If allow extras is true, don't keep eating - if(get_allow_extras()) - break; + // We could break here for allow extras, but we don't // If any positionals remain, don't keep eating if(_count_remaining_positionals() > 0) diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index ba86ca87..e306c7d9 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -302,11 +302,12 @@ TEST_F(TApp, RequiredOptsUnlimited) { run(); EXPECT_EQ(strs, std::vector({"one", "two"})); + // It's better to feed a hungry option than to feed allow_extras app.reset(); app.allow_extras(); run(); - EXPECT_EQ(strs, std::vector({"one"})); - EXPECT_EQ(app.remaining(), std::vector({"two"})); + EXPECT_EQ(strs, std::vector({"one", "two"})); + EXPECT_EQ(app.remaining(), std::vector({})); app.reset(); app.allow_extras(false); @@ -335,11 +336,12 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) { run(); EXPECT_EQ(strs, std::vector({"one", "two"})); + // It's better to feed a hungry option than to feed allow_extras app.reset(); app.allow_extras(); run(); - EXPECT_EQ(strs, std::vector({"one"})); - EXPECT_EQ(app.remaining(), std::vector({"two"})); + EXPECT_EQ(strs, std::vector({"one", "two"})); + EXPECT_EQ(app.remaining(), std::vector({})); app.reset(); app.allow_extras(false);