diff options
Diffstat (limited to 'lib/puppet/interface/action_manager.rb')
-rw-r--r-- | lib/puppet/interface/action_manager.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb index 27a982929..8629b4cbe 100644 --- a/lib/puppet/interface/action_manager.rb +++ b/lib/puppet/interface/action_manager.rb @@ -1,32 +1,36 @@ +require 'puppet/interface/action_builder' + module Puppet::Interface::ActionManager # Declare that this app can take a specific action, and provide # the code to do so. def action(name, &block) - @actions ||= [] + @actions ||= {} name = name.to_s.downcase.to_sym + raise "Action #{name} already defined for #{self}" if action?(name) - @actions << name - if self.is_a?(Class) - define_method(name, &block) - else - meta_def(name, &block) - end + action = Puppet::Interface::ActionBuilder.build(self, name, &block) + + @actions[name] = action end def actions - @actions ||= [] - result = @actions.dup + @actions ||= {} + result = @actions.keys if self.is_a?(Class) and superclass.respond_to?(:actions) result += superclass.actions elsif self.class.respond_to?(:actions) result += self.class.actions end - result.sort { |a,b| a.to_s <=> b.to_s } + result.sort + end + + def get_action(name) + @actions[name].dup end def action?(name) - actions.include?(name.to_sym) + actions.include?(name) end end |