-
Notifications
You must be signed in to change notification settings - Fork 19
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
Forbidden optional parameters set to nil
when not present in command line
#94
Comments
Good catch — that is indeed supposed to be Will fix! |
Sure!. But my use case made the difference: def attrs
{
force: opts[:force]
}.compact
end |
This is now released in 2.15.7. |
Thanks for the quick reaction 🥇 |
It looks like previously the keys weren't set at all in the Not requesting any change to this fix, just a warning to people who may have previously been checking for the existence of the key (e.g. |
@scotje Oh no, that’s unfortunately. I do believe that the new (current) behavior is more correct, but “correctness” is a gray area now. I feel that now is a good time for me to set up an integration test with |
This particular issue was with PDK (which is the primary Cri-dependent tool I work with these days). You can see the fix here, it was honestly mostly with our tests being overly strict about options hash being passed around: puppetlabs/pdk#672 |
In r10k we need to distinguish between the cli being invoked without a flag and being invoked with an explicit false. Is there an alternative way to do this? |
At the moment, there no longer is. Can you elaborate on where you need this behavior? I have a few ideas on how this behavior could be made available again without breaking anything else, though I’ll need a bit of time to implement it. |
I will reopen this ticket because there are still issues with it. |
By setting default values for options explicitly, i.e. using #[]=, it becomes impossible to distinguish beteen explicity-specified options and implicitly-defaulted options. By using Hash#new, it becomes possible to return default values but not have them explicitly set as keys. See #94.
Here’s an enhancement which I believe makes this situation a bit more clear: #99. It should meet @eguzki’s requirements as well as be useful for Puppet. @pcarlisle Can you check whether this makes sense to you? option :a, :animal, 'add animal', default: 'giraffe', argument: :required
run do |opts, args, cmd|
puts "Animal = #{opts[:animal]}"
puts "Option given? #{opts.key?(:animal)}"
end % ./run --animal=donkey
Animal = donkey
Option given? true
% ./run --animal=giraffe
Animal = giraffe
Option given? true
% ./run
Animal = giraffe
Option given? false |
Note that #99 does require a small change to pdk’s tests, which I’ve prepared: puppetlabs/pdk#674 |
Yes, we have a configuration file which can be overridden by command line options and we only wish to do that when they are explicitly passed. The change in #99 looks like it would work for this. |
cri 2.15.7 changed the behaviour of the options hash so that unspecified flags are defaulted to an explicit `false` rather than being unset. From the look of denisdefreyne/cri#94 though this behaviour may be changing in the next release so lets pin cri to a maximum of 2.15.6 for now until the behaviour stabilises and then we can make the necessary changes. /cc puppetlabs#674
This is now fixed in the 2.15.8 release. Note that the behavior has changed slightly: it is now more closely aligned with the behavior in 2.15.6, and better defined. See the 2.15.8 release notes for details. |
I think there was still a breaking change in here somewhere. See voxpupuli/onceover#256 |
cri 2.15.7 changed the behaviour of the options hash so that unspecified flags are defaulted to an explicit `false` rather than being unset. From the look of denisdefreyne/cri#94 though this behaviour may be changing in the next release so lets pin cri to a maximum of 2.15.6 for now until the behaviour stabilises and then we can make the necessary changes. /cc puppetlabs#674
Currently, forbidden optional parameters set to
nil
when not present in command line. From documentation, it is expected to returnfalse
The text was updated successfully, but these errors were encountered: