diff options
author | Jacob Helwig <jacob@puppetlabs.com> | 2011-07-21 16:50:02 -0700 |
---|---|---|
committer | Jacob Helwig <jacob@puppetlabs.com> | 2011-07-21 16:50:02 -0700 |
commit | 9c78759af57967d64eceeeb704a6673b81a76f30 (patch) | |
tree | 62474dc08399a36996b414dfa6c829978cc47a90 /lib/puppet/interface/option_builder.rb | |
parent | ba6230b6039d62b0713c9d5e3ff61a68f70ef723 (diff) | |
parent | 5e2a3d200b74eef9549e3e2a5bdbe2a23ae7fac1 (diff) | |
download | puppet-9c78759af57967d64eceeeb704a6673b81a76f30.tar.gz puppet-9c78759af57967d64eceeeb704a6673b81a76f30.tar.xz puppet-9c78759af57967d64eceeeb704a6673b81a76f30.zip |
Merge branch '2.7.x'
* 2.7.x:
(#7123) Make `find` the default action...
(#7123) Support runtime setting of 'default' on actions.
(#6787) Add `default_to` for options.
(#6857) Password disclosure when changing a user's password
Diffstat (limited to 'lib/puppet/interface/option_builder.rb')
-rw-r--r-- | lib/puppet/interface/option_builder.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/puppet/interface/option_builder.rb b/lib/puppet/interface/option_builder.rb index 5676ec977..c87adc2c0 100644 --- a/lib/puppet/interface/option_builder.rb +++ b/lib/puppet/interface/option_builder.rb @@ -51,4 +51,17 @@ class Puppet::Interface::OptionBuilder def required(value = true) @option.required = value end + + def default_to(&block) + block or raise ArgumentError, "#{@option} default_to requires a block" + if @option.has_default? + raise ArgumentError, "#{@option} already has a default value" + end + # Ruby 1.8 treats a block without arguments as accepting any number; 1.9 + # gets this right, so we work around it for now... --daniel 2011-07-20 + unless block.arity == 0 or (RUBY_VERSION =~ /^1\.8/ and block.arity == -1) + raise ArgumentError, "#{@option} default_to block should not take any arguments" + end + @option.default = block + end end |