-
Notifications
You must be signed in to change notification settings - Fork 361
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
[WIP] Add radio groups #234
[WIP] Add radio groups #234
Conversation
Radio groups are named so after HTML radio buttons (named so after old style car radio station select buttons). A radio group is a numeric property of an option. All options having the same radio_id() become mutually exclusive and at least one of them is required to be specified. Example: CLI::Option *aopt = app.add_option("-a,--aopt", a "Option A")->radio_id(1); CLI::Option *bopt = app.add_option("-b,--bopt", b "Option B")->radio_id(1); CLI::Option *copt = app.add_flag("-c,--copt", c, "Option C")->radio_id(1); Resolves CLIUtils#88
@henryiii, please tell me what you think about this approach. |
There are several issues on the surface. I like strings better than numbers; you should have named radio_ids rather than hoping you remember what number they are. Also, minimum and maximum are not available here, it's 1 option in the group only (in keeping with a normal radio button, though). Mostly though, it seems like this should share something programmatically, rather than just by contract with the user and a magic number or string. I'll look at the underlying design a bit more and get back to you again. Also the Option Group idea in #227 might solve some/all of this. |
The error with list of options is nice, by the way. |
Numbers were selected because I hate strings as a C (not C++) programmer and because:
All in all, I don't see any advantages in using strings unless they are displayed to the user, and since I don't show my radio groups to the user, I decided to go with the numbers. I didn't understand the comment regarding "the minimum and maximum", by the way. I agree though that if option groups are implemented as full-scale objects with properties, that could be better. |
@AlexanderAmelkin what do you think of the direction taken in #227. Is there something that can be done in the constructors of option_groups that might make it more user friendly and useful? |
CLI11 is a C++ library, not C. Though I do know there is a C11. :)
Yes. But if there is a measurable impact on the performance of CLI11 due to this one check, CLI11 is in trouble. CLI11 is, by its very nature, manipulating strings. Its input are strings, options are named with strings, etc. And it generally is not manipulating a massive number of strings and options.
A programmer spends 10% of their time writing code, 20% of their time reading code (often code they wrote), and 70% of there time debugging code. Numbers don't tell me why you grouped something. A name might.
Printing helpful help would be nice. A user needs to know what options are required in a group.
Yes, you can't enforce that someone does this, but it would be the best way to use an integer ID value. I notice you did not do this for your example, though.
What if you want to require 2 options from a list of 5? Or exactly 1 option vs. 1 or more options? My biggest problem with using integers is, though, what happens someone writes a file with some options, and uses option ID 0. Then someone (maybe someone else or a very forgetful person) adds another file with a new option group, but also picks ID 0? This is less likely with strings, and is more understandable if it does happen. Did you look at #227? Your feedback there would be useful. I'm going to try to work on a full Option group class idea just to see how it compares to the two approaches. |
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
========================================
- Coverage 100% 98.7% -1.3%
========================================
Files 12 12
Lines 2057 2090 +33
========================================
+ Hits 2057 2063 +6
- Misses 0 27 +27
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
========================================
- Coverage 100% 98.7% -1.3%
========================================
Files 12 12
Lines 2057 2090 +33
========================================
+ Hits 2057 2063 +6
- Misses 0 27 +27
Continue to review full report at Codecov.
|
Thanks for this, but I think that the option groups feature solves this. Please feel free to comment on any deficiencies or features you need! |
Radio groups are named so after HTML radio buttons
(named so after old style car radio station select buttons).
A radio group is a numeric property of an Option.
All options having the same radio_id() become mutually
exclusive and at least one of them is required to be specified.
Example:
Resolves #88