summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/option.rb
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-15 15:34:24 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-15 15:34:24 -0700
commit0d0318f9f0eadff7f9934d3d02a7081bba05164c (patch)
treedfc6b3d976ac5acf822846c272bdb4451b10aeba /lib/puppet/interface/option.rb
parent3fe01a34e8397c30a00e7d47b4ac0b93198e1fcf (diff)
parentd80500f42367fa30a00dc12ef4b32b55b350b1ca (diff)
downloadpuppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.gz
puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.xz
puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.zip
Merge branch 'feature/2.7.x/6978-face-and-action-options-should-have-hooks-for-various-actions' into 2.7.x
Diffstat (limited to 'lib/puppet/interface/option.rb')
-rw-r--r--lib/puppet/interface/option.rb47
1 files changed, 34 insertions, 13 deletions
diff --git a/lib/puppet/interface/option.rb b/lib/puppet/interface/option.rb
index ccc2fbba7..2abcd4033 100644
--- a/lib/puppet/interface/option.rb
+++ b/lib/puppet/interface/option.rb
@@ -1,19 +1,6 @@
require 'puppet/interface'
class Puppet::Interface::Option
- attr_reader :parent
- attr_reader :name
- attr_reader :aliases
- attr_reader :optparse
- attr_accessor :desc
-
- def takes_argument?
- !!@argument
- end
- def optional_argument?
- !!@optional_argument
- end
-
def initialize(parent, *declaration, &block)
@parent = parent
@optparse = []
@@ -79,4 +66,38 @@ class Puppet::Interface::Option
raise "#{name.inspect} is an invalid option name" unless name.to_s =~ /^[a-z]\w*$/
name.to_sym
end
+
+
+ def takes_argument?
+ !!@argument
+ end
+ def optional_argument?
+ !!@optional_argument
+ end
+
+
+ attr_reader :parent, :name, :aliases, :optparse
+ attr_accessor :desc
+
+ attr_accessor :before_action
+ def before_action=(proc)
+ proc.is_a? Proc or raise ArgumentError, "before action hook for #{self} is a #{proc.class.name.inspect}, not a proc"
+ @before_action =
+ @parent.__send__(:__decorate, :before, __decoration_name(:before), proc)
+ end
+
+ attr_accessor :after_action
+ def after_action=(proc)
+ proc.is_a? Proc or raise ArgumentError, "after action hook for #{self} is a #{proc.class.name.inspect}, not a proc"
+ @after_action =
+ @parent.__send__(:__decorate, :after, __decoration_name(:after), proc)
+ end
+
+ def __decoration_name(type)
+ if @parent.is_a? Puppet::Interface::Action then
+ :"option #{name} from #{parent.name} #{type} decoration"
+ else
+ :"option #{name} #{type} decoration"
+ end
+ end
end