diff options
author | Michael Stahnke <stahnma@puppetlabs.com> | 2011-08-05 09:23:49 -0700 |
---|---|---|
committer | Michael Stahnke <stahnma@puppetlabs.com> | 2011-08-05 09:23:49 -0700 |
commit | 3daea902b29cfd8e126ed64247ddf28aa5ad3d76 (patch) | |
tree | cda7fff4d06c7f3607a84b260fd71adfd9704e3b /lib/puppet/interface/option.rb | |
parent | c8835ad0275c350b57884b81e485d9fc16699a21 (diff) | |
parent | 2185bb2804aeef6b419667951b2157b01404c694 (diff) | |
download | puppet-3daea902b29cfd8e126ed64247ddf28aa5ad3d76.tar.gz puppet-3daea902b29cfd8e126ed64247ddf28aa5ad3d76.tar.xz puppet-3daea902b29cfd8e126ed64247ddf28aa5ad3d76.zip |
Merge branch '2.7.x' into 2.7rc
Diffstat (limited to 'lib/puppet/interface/option.rb')
-rw-r--r-- | lib/puppet/interface/option.rb | 19 |
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) |