1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-02 13:43:52 +00:00

Restore humgry option prioritizing over allow_extras

This commit is contained in:
Henry Fredrick Schreiner 2017-11-22 13:55:16 -05:00 committed by Henry Schreiner
parent e2e88b78e0
commit da841b9f69
3 changed files with 9 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -302,11 +302,12 @@ TEST_F(TApp, RequiredOptsUnlimited) {
run();
EXPECT_EQ(strs, std::vector<std::string>({"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<std::string>({"one"}));
EXPECT_EQ(app.remaining(), std::vector<std::string>({"two"}));
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
app.reset();
app.allow_extras(false);
@ -335,11 +336,12 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
run();
EXPECT_EQ(strs, std::vector<std::string>({"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<std::string>({"one"}));
EXPECT_EQ(app.remaining(), std::vector<std::string>({"two"}));
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
app.reset();
app.allow_extras(false);