-
Notifications
You must be signed in to change notification settings - Fork 359
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
Allow general flag types #235
Conversation
9e7ccd4
to
abc972c
Compare
Codecov Report
@@ Coverage Diff @@
## master #235 +/- ##
======================================
Coverage 100% 100%
======================================
Files 12 12
Lines 2112 2212 +100
======================================
+ Hits 2112 2212 +100
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #235 +/- ##
==========================================
- Coverage 100% 99.09% -0.91%
==========================================
Files 12 12
Lines 2087 2102 +15
==========================================
- Hits 2087 2083 -4
- Misses 0 19 +19
Continue to review full report at Codecov.
|
b19b0a3
to
8b03ef9
Compare
One question is whether there should be a method on options to disable flag value overrides. for example you are able to specify but on the command line |
Not sure about the proper way to disable it, but I think an error is better than ignoring an issue. PS: I'll be traveling on vacation from tomorrow till Tuesday, so might not be able to do very complicated reviews for a while. |
8b03ef9
to
293d0b6
Compare
TODOs
|
For @henryiii And I made the operator[] function a template so there is only one in the code, but it may have the potential to generate a bunch of symbols if different string constants are used, so I may prefer the two overloads without the template, but I think either might be valid and have advantages/disadvantages, so i think it is your call? |
I generally avoid returning references, because this is not safe: int& value(int& x) {
return x;
}
int main() {
int x = 3;
auto y = value(x);
y = 4;
std::cout << x << " and " << y << std::endl;
} You have to write Now, disallowing copies helps somewhat, but it still might be more surprising to a novice programmer. Pointers are a bit more common and it's harder to make a mistake with auto. |
Just a thought; should flags that have defaults automatically get this disabled? That is, ->add_flag("--flag,--no-flag{false}", ...); Maybe should allow Edit: note this is two suggestions, the one below is an extension of this idea (possibly not a good one). In fact, it seems like that almost negates the need for the explicit setting; if a user did this: ->add_flag("--flag{true},--no-flag{false}", ...); That would mean no |
FYI, in the "files changed" tab you can queue up a list of accepted suggestions and commit them in one go. ;) |
I will change [] to return by pointer.
My hesitancy with that would be ->add_flag("--flag,--no-flag{false}", ...); you might still want to allow --flag=false, so I would a little hesitant to enable that by default with mixed usage, though it might be advisable if all flags list defaults. Also even if the disable_flag_override is selected if you specify ={} or =false then there is no error. right now if you were to do |
I haven't checked the code in detail, so not sure if it's even possible, but in the first half of that I was suggesting that
Would produce a half-way state, where |
We can merge, play with it a while, then tweak if needed. |
c6ec129
to
a733d3d
Compare
Did not know that, Our code reviews haven't used suggestions that much, maybe should start using that feature a little more |
do you have an opinion on the operator[] template, whether it should remain a template or split into 2 non-template overloads? |
Since it's a simple function, I'd prefer avoiding the template (mildly). Simpler compile, doesn't create extra symbols for different string types. Slightly nicer error message too. Not a strong preference though. And on the other side, you only have to have one unit test for the template instead of two. If was any longer, I'd lean toward the template instead (or having one call the other; rather makes sense since you are working around a compiler "feature" for |
It's pretty new, it might still even list "experimental" when using it. It's quite handy though. |
add some comments in readME about performance move operator[] to return const Option * Apply suggestions from code review Co-Authored-By: phlptp <top1@llnl.gov> update readme and add some IniTests and fix a bug from the tests add_flag_callback add a few tests to capture the different paths fix incorrectly updated CMAKE file, and add some subcommand test for option finding add disable_flag_override and work out some kinks in the find option functions add some more tests and fix a few bugs in as<> function for options Allow general flag types and default values, add shortcut notation for retrieving values
a733d3d
to
700db24
Compare
I moved to two functions and collapsed all the commits. I think I would lean away from ever putting on disable_flag_override by default. One of the drivers was a use case to have a default output for flags for example
In this case it is expected overrides would be fairly common and you wouldn't want to disable the overrides. |
I think this is ready. |
If merged this pull request will allow general flag values to be used, along with customized default values. It also introduces a shortcut syntax for retrieving flag and option values. Which is useful for allowing options with no storage variables.
this is similar notation to some other Command line libraries and could make transitioning to CLI easier
It also allows numbers to be used as short flags, so
-7
and similar is now allowedThis could be specified to have a default value like
-7{7}
in which case if the value -7 were passed it would produce a result of7
in the output.This PR addresses #123 and #124.