[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Daniel Pittman
daniel at puppetlabs.com
Tue May 10 08:16:01 UTC 2011
The following commit has been merged in the experimental branch:
commit 0d0318f9f0eadff7f9934d3d02a7081bba05164c
Merge: 3fe01a34e8397c30a00e7d47b4ac0b93198e1fcf d80500f42367fa30a00dc12ef4b32b55b350b1ca
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Fri Apr 15 15:34:24 2011 -0700
Merge branch 'feature/2.7.x/6978-face-and-action-options-should-have-hooks-for-various-actions' into 2.7.x
diff --combined lib/puppet/face/help.rb
index 8bd495f,a487eb2..0990255
--- a/lib/puppet/face/help.rb
+++ b/lib/puppet/face/help.rb
@@@ -13,13 -13,20 +13,21 @@@ Puppet::Face.define(:help, '0.0.1') d
desc "Which version of the interface to show help for"
end
+ default
when_invoked do |*args|
# Check our invocation, because we want varargs and can't do defaults
# yet. REVISIT: when we do option defaults, and positional options, we
# should rewrite this to use those. --daniel 2011-04-04
options = args.pop
if options.nil? or args.length > 2 then
+ if args.select { |x| x == 'help' } .length > 2 then
+ c = "\n !\"'),-./7:;<GIJLST\\_`abcdefhiklmnoprstuwx|}".split('')
+ i = <<'EOT' .to_i(36)
+ 2s7ytxy5vpj74kbab5xzf1ik2roinzlefaspjrzckiert5xbaxvwlku3a91w7y1rsdnenp51gwpulmnrp54nwdil36fjgjarab801y0r5a9nh1hdfgi99arn5c5t3zhxbvziu6wx5r1tb7lun7pro69nrxunqqixsh6qmmv0ms0i0yycqw3pystyzmiita0lpxynqsqkbjwadcx82n76wwpzbht8i8rgvqhqick8mk3cs3rvwdjookpgu0rxw4tcezned5sqz5x8z9vntyyz0s4h6hjhtwtbytsmmu7ltvdftaixc7fkt276sqm48ab4yv0ot9y26nz0xniy4pfl1x300lt6h9c8of49vf799ieuxwnoycsjlmtd4qntzit524j0tdn6n5ajmq3z10apjuhkzprvmu53z1gnacymnoforrz5mbqto062kckgw5463pxwzg8liglub4ubnr0dln1s6iy3ummxuhim7m5a7yedl3gyy6ow4qqtmsigv27lysooau24zpsccsvxddwygjprqpbwon7i9s1279m1fpinvva8mfh6bgmotrpxsh1c8rc83l3u0utf5i200yl7ui0ngcbcjyr4erzdee2tqk3fpjvb82t8xhncruhgn7j5dh2m914qzhb0gkoom47k6et7rp4tqjnrv0y2apk5qdl1x1hnbkkxup5ys6ip2ksmtpd3ipmrdtswxr5xwfiqtm60uyjr1v79irhnkrbbt4fwhgqjby1qflgwt9c1wpayzzucep6npgbn3f1k6cn4pug31u02wel4tald4hij8m5p49xr8u4ero1ucs5uht42o8nhpmpe7c7xf9t85i85m9m5kktgoqkgbu52gy5aoteyp8jkm3vri9fnkmwa5h60zt8otja72joxjb40p2rz2vp8f8q9nnggxt3x90pe5u4048ntyuha78q1oikhhpvw9j083yc3l00hz5ehv9c1au5gvctyapzprub289qruve9qsyuh75j04wzkemqw3uhisrfs92u1ahv2qlqxmorgob16c1vbqkxttkoyp2agkt0v5l7lec25p0jqun9y39k41h67aeb5ihiqsftxc9azmg31hc73dk8urlj88vgbmgt8yln9rchw60whgxvnv9zn6cxbr482svctswc5a07atj
+ EOT
+ 607.times{i,x=i.divmod(1035);a,b=x.divmod(23);print(c[a]*b)}
+ raise ArgumentError, "Such panic is really not required."
+ end
raise ArgumentError, "help only takes two (optional) arguments, a face name, and an action"
end
diff --combined lib/puppet/interface/action.rb
index 3c18c2a,3946b74..b942989
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@@ -7,8 -7,9 +7,9 @@@ class Puppet::Interface::Actio
raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/
@face = face
@name = name.to_sym
- @options = {}
attrs.each do |k, v| send("#{k}=", v) end
+
+ @options = {}
end
# This is not nice, but it is the easiest way to make us behave like the
@@@ -23,7 -24,7 +24,7 @@@
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
@@@ -84,11 -85,21 +85,21 @@@
internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym
file = __FILE__ + "+eval"
line = __LINE__ + 1
- wrapper = "def #{@name}(*args, &block)
- args << {} unless args.last.is_a? Hash
- args << block if block_given?
- self.__send__(#{internal_name.inspect}, *args)
- end"
+ wrapper = <<WRAPPER
+ def #{@name}(*args, &block)
+ if args.last.is_a? Hash then
+ options = args.last
+ else
+ args << (options = {})
+ end
+
+ action = get_action(#{name.inspect})
+ __invoke_decorations(:before, action, args, options)
+ rval = self.__send__(#{internal_name.inspect}, *args)
+ __invoke_decorations(:after, action, args, options)
+ return rval
+ end
+ WRAPPER
if @face.is_a?(Class)
@face.class_eval do eval wrapper, nil, file, line end
@@@ -123,7 -134,19 +134,19 @@@
(@options.keys + @face.options).sort
end
- def get_option(name)
- @options[name.to_sym] || @face.get_option(name)
+ def get_option(name, with_inherited_options = true)
+ option = @options[name.to_sym]
+ if option.nil? and with_inherited_options
+ option = @face.get_option(name)
+ end
+ option
+ end
+
+ ########################################################################
+ # Support code for action decoration; see puppet/interface.rb for the gory
+ # details of why this is hidden away behind private. --daniel 2011-04-15
+ private
+ def __decorate(type, name, proc)
+ @face.__send__ :__decorate, type, name, proc
end
end
diff --combined spec/unit/interface/action_builder_spec.rb
index 8f29c8a,cafdde4..aecaf19
--- a/spec/unit/interface/action_builder_spec.rb
+++ b/spec/unit/interface/action_builder_spec.rb
@@@ -12,10 -12,11 +12,11 @@@ describe Puppet::Interface::ActionBuild
end
it "should define a method on the face which invokes the action" do
- face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1')
- action = Puppet::Interface::ActionBuilder.build(face, :foo) do
- when_invoked do
- "invoked the method"
+ face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1') do
+ action :foo do
+ when_invoked do
+ "invoked the method"
+ end
end
end
@@@ -65,16 -66,5 +66,16 @@@
action.summary.should == "this is some text"
end
end
+
+ context "action defaulting" do
+ let :face do Puppet::Interface.new(:default_action, '0.0.1') end
+
+ it "should set the default to true" do
+ action = Puppet::Interface::ActionBuilder.build(face, :foo) do
+ default
+ end
+ action.default.should == true
+ end
+ end
end
end
diff --combined spec/unit/interface/action_manager_spec.rb
index 387faa0,0534a49..6a6c254
--- a/spec/unit/interface/action_manager_spec.rb
+++ b/spec/unit/interface/action_manager_spec.rb
@@@ -3,7 -3,6 +3,7 @@@ require 'spec_helper
# This is entirely an internal class for Interface, so we have to load it instead of our class.
require 'puppet/interface'
+require 'puppet/face'
class ActionManagerTester
include Puppet::Interface::ActionManager
@@@ -104,6 -103,7 +104,7 @@@ describe Puppet::Interface::ActionManag
@klass = Class.new do
include Puppet::Interface::ActionManager
extend Puppet::Interface::ActionManager
+ def __invoke_decorations(*args) true end
end
@instance = @klass.new
end
@@@ -214,23 -214,6 +215,23 @@@
end
end
+ describe "#action" do
+ it 'should add an action' do
+ subject.action(:foo) { }
+ subject.get_action(:foo).should be_a Puppet::Interface::Action
+ end
+
+ it 'should support default actions' do
+ subject.action(:foo) { default }
+ subject.get_default_action.should == subject.get_action(:foo)
+ end
+
+ it 'should not support more than one default action' do
+ subject.action(:foo) { default }
+ expect { subject.action(:bar) { default } }.should raise_error
+ end
+ end
+
describe "#get_action" do
let :parent_class do
parent_class = Class.new(Puppet::Interface)
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list