-
Notifications
You must be signed in to change notification settings - Fork 355
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
Option delimiter #240
Option delimiter #240
Conversation
@henryiii if you are ok with a few breaking changes regarding the delimiter argument with some of the options, I think you could eliminate a couple of the overloads for options that have the delimiter argument in them. Since there is now a delimiter(char) function on the Option. |
Codecov Report
@@ Coverage Diff @@
## master #240 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 12 12
Lines 2212 2212
=====================================
Hits 2212 2212
Continue to review full report at Codecov.
|
I think that's better. And API that is not in a released version of CLI11 is fine to change! I strongly prefer Option methods, since they are easy to read, rather than positional arguments that do not describe what they do. |
Let me know when you are ready for final review & merge. Do you want to drop the extra argument on |
Please update the readme as well (optionally the changelog too, but that's completely optional, since it can cause conflicts when merging multiple PRs, and is pretty easy to do later). |
… in App, and update the tests to match updated calls
I think I will let you do the changelog, that is probably worth making sure the style is consistent. I updated the readMe. Let me know if I need to add the defaulted version as a separate overload for vectors. If so it might be desirable to have a test that actually needs that and wouldn't compile without the overload. |
That would be great, especially since I want to try adding a function to make the overload unneeded. But that's after this PR gets merged. Edit: Added Issue #241. |
Thanks! |
Great work |
What about |
This PR addresses an issue I came across working on the Validators. The problem was with vectors and Validators if you wanted a vector with a range of say [0, 20] There are options for Validating individual elements but not after the conversion if you also wanted to use a custom delimiter. Furthermore if you wanted to require 3 elements, that had to be 3 elements before the delimiter was applied.
What is comes down to is the delimiter was being applied too late, and had to be applied in a bunch of places if you wanted to use it.
The solution was to move it as part of the Option class. Any option can now have a delimiter, and the delimiter is applied when the results are loaded into an option. This can allow options that require multiple arguments to accept them as a comma separated list or something along those lines and have that meet the requirement.
One twist on the add_complex is you could add ->delimiter('+') and it would accept argument such as "3+2j" as a single command line argument since the + on +2j is redundant. a negative number would still need to be written like 4+-2j for that to work.
My use case I wanted to able to specify a bunch of flags like --flags=flag1,flag2,flag3,.. and have them checked against a hash table. That would only work if the delimiter was applied before the Validator.