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

Group merge #1039

Merged
merged 4 commits into from
May 20, 2024
Merged

Group merge #1039

merged 4 commits into from
May 20, 2024

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented May 10, 2024

This PR adds a mechanism to hide groups but have their options visible as part of the parent.
This works for option group names starting with a '+'

for example

 CLI::App app;

    bool flag = false;
    std::optional<bool> optional_flag = std::nullopt;

    app.add_option("--tester");
    auto *m1=app.add_option_group("+tester");

    m1->add_option("--flag", flag, "description");
    m1->add_option("--optional_flag", optional_flag, "description");

    CLI11_PARSE(app,argc, argv);

will produce help as

Options:
  -h,--help                   Print this help message and exit
  --tester
  --flag BOOLEAN              description
  --optional_flag BOOLEAN     description

instead of

Options:
  -h,--help                   Print this help message and exit
  --tester
[Option Group: tester]
  Options:
    --flag BOOLEAN              description
    --optional_flag BOOLEAN     description

Fixes issue #1034 and a few other past issues or questions

Copy link

codecov bot commented May 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e4ee3af) to head (27137c6).
Report is 27 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1039    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           17        17            
  Lines         4546      4569    +23     
  Branches         0       976   +976     
==========================================
+ Hits          4546      4569    +23     

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

@phlptp phlptp requested a review from henryiii May 16, 2024 03:10
@phlptp
Copy link
Collaborator Author

phlptp commented May 17, 2024

@henryiii unless I hear some objections I am going to merge this on Monday.

@henryiii
Copy link
Collaborator

Sounds good. Let me know if there’s anything specific to review. At PyCon currently.

@phlptp
Copy link
Collaborator Author

phlptp commented May 17, 2024

Mostly if you have any concerns about the notation itself and having slightly different behavior depending on the option group name. I know there have been several requests for this capability and I am a little reticent to add more modifiers and options, so this seemed like a nice solution.

@henryiii
Copy link
Collaborator

Especially because I have options that belong together, but are in different groups.

That wouldn't be covered by this?

@phlptp
Copy link
Collaborator Author

phlptp commented May 19, 2024

Especially because I have options that belong together, but are in different groups.

That wouldn't be covered by this?

It should be. The way the mechanic works is that the option would get associated with a parent group, that could be the main app or a sub_group. So you could tie any number of sub_groups together for help display as part of the main app or in another sub group.

@phlptp phlptp merged commit 08d840b into CLIUtils:main May 20, 2024
55 checks passed
@phlptp phlptp deleted the group_merge branch May 20, 2024 18:15
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.

2 participants