summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/option.rb
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-07-21 16:50:02 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-07-21 16:50:02 -0700
commit9c78759af57967d64eceeeb704a6673b81a76f30 (patch)
tree62474dc08399a36996b414dfa6c829978cc47a90 /lib/puppet/interface/option.rb
parentba6230b6039d62b0713c9d5e3ff61a68f70ef723 (diff)
parent5e2a3d200b74eef9549e3e2a5bdbe2a23ae7fac1 (diff)
downloadpuppet-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.rb')
-rw-r--r--lib/puppet/interface/option.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/puppet/interface/option.rb b/lib/puppet/interface/option.rb
index 3cd930acf..01f6f2307 100644
--- a/lib/puppet/interface/option.rb
+++ b/lib/puppet/interface/option.rb
@@ -6,6 +6,7 @@ class Puppet::Interface::Option
def initialize(parent, *declaration, &block)
@parent = parent
@optparse = []
+ @default = nil
# Collect and sort the arguments in the declaration.
dups = {}
@@ -81,8 +82,26 @@ class Puppet::Interface::Option
!!@required
end
+ def has_default?
+ !!@default
+ end
+
+ def default=(proc)
+ required and raise ArgumentError, "#{self} can't be optional and have a default value"
+ proc.is_a? Proc or raise ArgumentError, "default value for #{self} is a #{proc.class.name.inspect}, not a proc"
+ @default = proc
+ end
+
+ def default
+ @default and @default.call
+ end
+
attr_reader :parent, :name, :aliases, :optparse
attr_accessor :required
+ def required=(value)
+ has_default? and raise ArgumentError, "#{self} can't be optional and have a default value"
+ @required = value
+ end
attr_accessor :before_action
def before_action=(proc)