summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-07-20 12:35:22 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-07-20 17:07:10 -0700
commitfd6a653cb32cb03e339655862c526fd5dccbfcf0 (patch)
tree30e7f89b5a2e9cfa96a1da2e209d0f88c4d30dc9
parentb75b1c19ecf6c278b065d203ac8486fa598caa8b (diff)
downloadpuppet-fd6a653cb32cb03e339655862c526fd5dccbfcf0.tar.gz
puppet-fd6a653cb32cb03e339655862c526fd5dccbfcf0.tar.xz
puppet-fd6a653cb32cb03e339655862c526fd5dccbfcf0.zip
(#7123) Support runtime setting of 'default' on actions.
Given the inheritance model for actions, we are sometimes going to need to set them to 'default' at runtime, rather than during their static declaration. Add tests to verify that this works correctly, and update the code to ensure that happens. This gives up caching of the default action, but this should be an extremely rare operation - pretty much only CLI invocation, really. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
-rw-r--r--lib/puppet/interface/action_manager.rb15
-rwxr-xr-xspec/unit/interface/action_spec.rb18
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb
index fbf588d7d..5c9af4f96 100644
--- a/lib/puppet/interface/action_manager.rb
+++ b/lib/puppet/interface/action_manager.rb
@@ -7,13 +7,14 @@ module Puppet::Interface::ActionManager
require 'puppet/interface/action_builder'
@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
+
+ if action.default and current = get_default_action
+ raise "Actions #{current.name} and #{name} cannot both be default"
end
+
@actions[action.name] = action
end
@@ -61,7 +62,11 @@ module Puppet::Interface::ActionManager
end
def get_default_action
- @default_action
+ default = actions.map {|x| get_action(x) }.select {|x| x.default }
+ if default.length > 1
+ raise "The actions #{default.map(&:name).join(", ")} cannot all be default"
+ end
+ default.first
end
def action?(name)
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index dbbf84778..d71a7d000 100755
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -597,4 +597,22 @@ describe Puppet::Interface::Action do
end
end
end
+
+ context "runtime manipulations" do
+ subject do
+ Puppet::Interface.new(:runtime_manipulations, '1.0.0') do
+ action :foo do
+ when_invoked do |options| options end
+ end
+ end
+ end
+
+ let :action do subject.get_action :foo end
+
+ it "should be the face default action if default is set true" do
+ subject.get_default_action.should be_nil
+ action.default = true
+ subject.get_default_action.should == action
+ end
+ end
end