Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of min/max for subcommand #51

Merged
merged 5 commits into from
Nov 22, 2017
Merged

Refactor of min/max for subcommand #51

merged 5 commits into from
Nov 22, 2017

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented Nov 22, 2017

The old required_subcommand had several issues. This PR fixes those with a more thoughtful solution. The range of allowed subcommands can now be explicitly set, and CLI11 finally stops trying to match subcommands after the max number allowed is obtained. The changes:

  • require_subcommand now has a two-argument form, with min and max. Setting max to 0 means unlimited subcommands.
  • The negative value on the single argument form has been changed to the more useful "At most" -N subcommands. So -1 would mean 0 or 1. (Previously: would set 1 or more for any negative argument)
  • The error type is now the correct "ExtrasError" (or whatever the final subcommand does) instead of weird RequiredError if you have too many subcommands.
  • The maximum number of subcommands is inherited, as well. This is intended to allow someone who prefers -1 to set the default once. It only affects subcommands that have subcommands, obviously.

I've left .require_subcommand() as setting 1 or more, though 1 might be better; I did that because 1 is intuitive for someone requiring 1 subcommand, and 1 or more is not obtainable with a single argument otherwise (and is rather undiscoverable as .require_subcommand(1,0)).

As part of the extended testing, I've reduced the "grabbyness" of the unlimited argument options. They now no longer eat up options if positionals remain (including unlimited positionals).

@codecov
Copy link

codecov bot commented Nov 22, 2017

Codecov Report

Merging #51 into master will decrease coverage by 0.07%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
- Coverage   99.67%   99.59%   -0.08%     
==========================================
  Files           9        9              
  Lines        1241     1249       +8     
  Branches      251      252       +1     
==========================================
+ Hits         1237     1244       +7     
- Misses          4        5       +1
Impacted Files Coverage Δ
include/CLI/App.hpp 99.28% <93.75%> (-0.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1624b1f...a736bdf. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 22, 2017

Codecov Report

Merging #51 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage    99.6%   99.76%   +0.16%     
==========================================
  Files           9        9              
  Lines        1256     1289      +33     
  Branches      252      257       +5     
==========================================
+ Hits         1251     1286      +35     
+ Misses          5        3       -2
Impacted Files Coverage Δ
include/CLI/App.hpp 100% <100%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2deeca...c2115e1. Read the comment docs.

@henryiii henryiii added this to the v1.3 milestone Nov 22, 2017
@henryiii henryiii merged commit da841b9 into master Nov 22, 2017
@henryiii henryiii deleted the reqsubcom branch November 22, 2017 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant