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

Feature: Improved command-line arguments parsing #83

Merged
merged 11 commits into from
Jan 10, 2024

Conversation

dragonmux
Copy link
Member

In this PR we seek to improve the state of the command line arguments parser by implementing two new features that solve usability problems and bring us closer to parity with Rust's Clap and Python's argparse.

The first of these new features is option exclusivity, whereby you can define multiple options at a parsing level to be exclusive of one another and bypass requirements checks for normal options - this is done with the new options_t helper .exclusive() and allows, eg, --version and --help to be defined and made exclusive of each other + uncaring of other arguments requirements validity.

The second of these features is option globalness, whereby an option can be defined to be "global" (visible to its level and all parsing levels below that) such as a --help option that should appear on every level of parsing (through optionSet_t barriers) to improve the usage of the parser.

@dragonmux dragonmux added the enhancement New feature or request label Jan 9, 2024
Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (1fba992) 89.18% compared to head (b74a01b) 89.24%.

Files Patch % Lines
impl/command_line/arguments.cxx 84.88% 10 Missing and 3 partials ⚠️
impl/command_line/options.cxx 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
+ Coverage   89.18%   89.24%   +0.06%     
==========================================
  Files          47       47              
  Lines        3459     3516      +57     
  Branches      669      688      +19     
==========================================
+ Hits         3085     3138      +53     
- Misses        338      339       +1     
- Partials       36       39       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@amyspark amyspark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Some nits here and there, we've discussed the std::for_each at length and I agree it can improve readability of the lambda on certain uses (like this one).

substrate/command_line/arguments Show resolved Hide resolved
impl/command_line/arguments.cxx Outdated Show resolved Hide resolved
impl/command_line/arguments.cxx Show resolved Hide resolved
dragonmux and others added 9 commits January 10, 2024 00:30
…eArgument() to be able to take a set of options to recognise through the recursion step
…of global options through recursive arguments_t::parseFrom() calls
…bypass the required arguments checking if exactly one is given
A broken `= default;` in the header is recoverable by forward declaring
in the header, then using it in a translation unit (once the class is
complete).
@dragonmux dragonmux force-pushed the feature/improved-args-parsing branch from b7c8c48 to dee2062 Compare January 10, 2024 00:30
…r `noexcept` markings noting that std::multiset can throw when copied
@dragonmux dragonmux force-pushed the feature/improved-args-parsing branch from dee2062 to b74a01b Compare January 10, 2024 01:03
@amyspark amyspark self-requested a review January 10, 2024 01:54
@dragonmux dragonmux merged commit b74a01b into main Jan 10, 2024
166 of 167 checks passed
@dragonmux dragonmux deleted the feature/improved-args-parsing branch January 10, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants