mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 05:53:52 +00:00
Restore humgry option prioritizing over allow_extras
This commit is contained in:
parent
e2e88b78e0
commit
da841b9f69
@ -17,7 +17,7 @@
|
|||||||
* Failure messages are now customizable, with a shorter default [#52](https://github.com/CLIUtils/CLI11/pull/52)
|
* 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)
|
* `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)
|
* 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
|
## Version 1.2
|
||||||
|
|
||||||
|
@ -1392,9 +1392,7 @@ class App {
|
|||||||
bool already_ate_one = false; // Make sure we always eat one
|
bool already_ate_one = false; // Make sure we always eat one
|
||||||
while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
|
while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
|
||||||
if(already_ate_one) {
|
if(already_ate_one) {
|
||||||
// If allow extras is true, don't keep eating
|
// We could break here for allow extras, but we don't
|
||||||
if(get_allow_extras())
|
|
||||||
break;
|
|
||||||
|
|
||||||
// If any positionals remain, don't keep eating
|
// If any positionals remain, don't keep eating
|
||||||
if(_count_remaining_positionals() > 0)
|
if(_count_remaining_positionals() > 0)
|
||||||
@ -1471,9 +1469,7 @@ class App {
|
|||||||
bool already_ate_one = false; // Make sure we always eat one
|
bool already_ate_one = false; // Make sure we always eat one
|
||||||
while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
|
while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
|
||||||
if(already_ate_one) {
|
if(already_ate_one) {
|
||||||
// If allow extras is true, don't keep eating
|
// We could break here for allow extras, but we don't
|
||||||
if(get_allow_extras())
|
|
||||||
break;
|
|
||||||
|
|
||||||
// If any positionals remain, don't keep eating
|
// If any positionals remain, don't keep eating
|
||||||
if(_count_remaining_positionals() > 0)
|
if(_count_remaining_positionals() > 0)
|
||||||
|
@ -302,11 +302,12 @@ TEST_F(TApp, RequiredOptsUnlimited) {
|
|||||||
run();
|
run();
|
||||||
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
|
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.reset();
|
||||||
app.allow_extras();
|
app.allow_extras();
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(strs, std::vector<std::string>({"one"}));
|
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
|
||||||
EXPECT_EQ(app.remaining(), std::vector<std::string>({"two"}));
|
EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
|
||||||
|
|
||||||
app.reset();
|
app.reset();
|
||||||
app.allow_extras(false);
|
app.allow_extras(false);
|
||||||
@ -335,11 +336,12 @@ TEST_F(TApp, RequiredOptsUnlimitedShort) {
|
|||||||
run();
|
run();
|
||||||
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
|
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.reset();
|
||||||
app.allow_extras();
|
app.allow_extras();
|
||||||
run();
|
run();
|
||||||
EXPECT_EQ(strs, std::vector<std::string>({"one"}));
|
EXPECT_EQ(strs, std::vector<std::string>({"one", "two"}));
|
||||||
EXPECT_EQ(app.remaining(), std::vector<std::string>({"two"}));
|
EXPECT_EQ(app.remaining(), std::vector<std::string>({}));
|
||||||
|
|
||||||
app.reset();
|
app.reset();
|
||||||
app.allow_extras(false);
|
app.allow_extras(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user