Skip to content
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

Don’t set default options as explicit keys #99

Merged
merged 1 commit into from
Jun 8, 2019
Merged

Conversation

denisdefreyne
Copy link
Owner

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.

For example:

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

See #94.

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.
@denisdefreyne
Copy link
Owner Author

Marking as WIP because this change causes some pdk tests to fail.

@denisdefreyne
Copy link
Owner Author

Here’s a fix for pdk: puppet/pdk#674

@pcarlisle
Copy link

I've tested this with r10k and it solves my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants