-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 -ve values for int, float & duration #1262
Conversation
@@ -197,10 +197,8 @@ func (f *IntFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceCon | |||
if err != nil { | |||
return err | |||
} | |||
if value > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to tell from the commit that introduced this check, because it happens to also be the commit that introduced YAML parsing, but I assume the intent here was to avoid calling Set
on the flag set if the value wasn't explicitly specified. In an ideal world, I think we'd want isc.Int
to return value, ok, err
, so we would know whether the value was explicitly set as the zero value, versus just defaulting to zero.
While it's also an imperfect solution, what are your thoughts on keeping a check for value != 0
instead of > 0
? We wouldn't know whether or not the value was actually set if it's zero, but the key difference in behavior is that we would report false
for IsSet
, which is closer to the current behavior, and, if I had to guess, more likely than the case where 0
is explicitly set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually thinking about it a bit more we want to check that the value from yaml is not the same as the default value for that flag and only then set it. Then this would take care of both the issues. i.e we would report IsSet only if the value from yaml is different from flag default and also allow for range of values. This way the value from yaml could be zero as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rliebz Looking at it further the isc.XXX(f.Name) will return an error if the flag isnt found in the input source. So there is no chance of the Set being called in that case. Added a small unit test to verify that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI #1373
I don't know if this is my code causing the problem, or the change in this PR, and I'm not knowledgeable enough to figure it out. Maybe you guys can find out?
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
Closing this as it has become stale. |
This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant. |
@albttx i'll take a look at it this week |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rad! Thanks! 🙇🏼 🎉
Amazing, thanks 👍 |
What type of PR is this?
What this PR does / why we need it:
This PR allows negative values for int64, float64 and duration flags from alternate input sources
Which issue(s) this PR fixes:
Fixes #1199
Special notes for your reviewer:
Testing
Added 3 tests
Release Notes