diff options
| author | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-15 15:31:19 -0700 |
|---|---|---|
| committer | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-15 15:31:19 -0700 |
| commit | 9264526a7cd45c9ff5767bc6c85585eb19f01f63 (patch) | |
| tree | 4e8131a037b6352d0d3d52d7650dd9c1acf63465 /lib/puppet/interface | |
| parent | ba9bd88b8b60ebe567a6d78d70782610cc281213 (diff) | |
| download | puppet-9264526a7cd45c9ff5767bc6c85585eb19f01f63.tar.gz puppet-9264526a7cd45c9ff5767bc6c85585eb19f01f63.tar.xz puppet-9264526a7cd45c9ff5767bc6c85585eb19f01f63.zip | |
(#7115) Enable default actions.
This also enables the 'help' action on the 'help'
face to serve as a default action.
Reviewed-By: Daniel Pittman
Reviewed-By: Nick Lewis
Diffstat (limited to 'lib/puppet/interface')
| -rw-r--r-- | lib/puppet/interface/action.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/interface/action_builder.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/interface/action_manager.rb | 9 |
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index db338e39e..3c18c2aaf 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -23,7 +23,7 @@ class Puppet::Interface::Action attr_reader :name def to_s() "#{@face}##{@name}" end - attr_accessor :summary + attr_accessor :default, :summary # Initially, this was defined to allow the @action.invoke pattern, which is # a very natural way to invoke behaviour given our introspection diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb index 34bb3fa44..639d8fc7f 100644 --- a/lib/puppet/interface/action_builder.rb +++ b/lib/puppet/interface/action_builder.rb @@ -29,6 +29,10 @@ class Puppet::Interface::ActionBuilder @action.add_option(option) end + def default + @action.default = true + end + def summary(text) @action.summary = text end diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb index d75697afa..440be2d1b 100644 --- a/lib/puppet/interface/action_manager.rb +++ b/lib/puppet/interface/action_manager.rb @@ -5,8 +5,13 @@ module Puppet::Interface::ActionManager # the code to do so. def action(name, &block) @actions ||= {} + @default_action ||= nil raise "Action #{name} already defined for #{self}" if action?(name) action = Puppet::Interface::ActionBuilder.build(self, name, &block) + if action.default + raise "Actions #{@default_action.name} and #{name} cannot both be default" if @default_action + @default_action = action + end @actions[action.name] = action end @@ -50,6 +55,10 @@ module Puppet::Interface::ActionManager return result end + def get_default_action + @default_action + end + def action?(name) actions.include?(name.to_sym) end |
