[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:31 UTC 2011


The following commit has been merged in the experimental branch:
commit a594563919a2342e1ea542f8f18ed187ab9ecad3
Merge: 9adcb194a75df4e0f0570c20bfa90686ed078265 4efba7148a79fcd099b4eb9bd17cbb2d785f5fb8
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Tue Apr 19 10:34:05 2011 -0700

    Merge branch 'bug/2.7.x/7132-a-summary-with-a-newline-is-accepted' into 2.7.x

diff --combined lib/puppet/interface/action.rb
index 412e394,860ce40..f6273d1
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@@ -24,8 -24,21 +24,21 @@@ class Puppet::Interface::Actio
    attr_reader :name
    def to_s() "#{@face}##{@name}" end
  
-   attr_accessor :default, :summary
+   attr_accessor :default
  
+   ########################################################################
+   # Documentation stuff, whee!
+   attr_accessor :summary, :description
+   def summary=(value)
+     value = value.to_s
+     value =~ /\n/ and
+       raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
+ 
+     @summary = value
+   end
+ 
+ 
+   ########################################################################
    # Initially, this was defined to allow the @action.invoke pattern, which is
    # a very natural way to invoke behaviour given our introspection
    # capabilities.   Heck, our initial plan was to have the faces delegate to
@@@ -83,10 -96,10 +96,10 @@@
      # idea how motivated we were to make this cleaner.  Sorry. --daniel 2011-03-31
  
      internal_name = "#{@name} implementation, required on Ruby 1.8".to_sym
 -    file = __FILE__ + "+eval"
 -    line = __LINE__ + 1
 +    file    = __FILE__ + "+eval"
 +    line    = __LINE__ + 1
      wrapper = <<WRAPPER
 -def #{@name}(*args, &block)
 +def #{@name}(*args)
    if args.last.is_a? Hash then
      options = args.last
    else
@@@ -94,7 -107,6 +107,7 @@@
    end
  
    action = get_action(#{name.inspect})
 +  action.validate_args(args)
    __invoke_decorations(:before, action, args, options)
    rval = self.__send__(#{internal_name.inspect}, *args)
    __invoke_decorations(:after, action, args, options)
@@@ -143,15 -155,6 +156,15 @@@ WRAPPE
      option
    end
  
 +  def validate_args(args)
 +    required = options.map do |name|
 +      get_option(name)
 +    end.select(&:required?).collect(&:name) - args.last.keys
 +
 +    return if required.empty?
 +    raise ArgumentError, "missing required options (#{required.join(', ')})"
 +  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
diff --combined spec/unit/interface/action_spec.rb
index fe2409b,72f1cca..5058ffc
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@@ -66,8 -66,8 +66,8 @@@ describe Puppet::Interface::Action d
        let :face do
          Puppet::Interface.new(:ruby_api, '1.0.0') do
            action :bar do
 -            when_invoked do |options|
 -              options
 +            when_invoked do |*args|
 +              args.last
              end
            end
          end
@@@ -82,11 -82,6 +82,11 @@@
          options = face.bar(:bar => "beer")
          options.should == { :bar => "beer" }
        end
 +
 +      it "should call #validate_args on the action when invoked" do
 +        face.get_action(:bar).expects(:validate_args).with([1, :two, 'three', {}])
 +        face.bar 1, :two, 'three'
 +      end
      end
    end
  
@@@ -173,24 -168,6 +173,24 @@@
          end
        }.should raise_error ArgumentError, /Option foo conflicts with existing option foo/i
      end
 +
 +    it "should fail when a required action option is not provided" do
 +      face = Puppet::Interface.new(:required_action_option, '0.0.1') do
 +        action(:bar) do
 +          option('--foo') { required }
 +          when_invoked { }
 +        end
 +      end
 +      expect { face.bar }.to raise_error ArgumentError, /missing required options \(foo\)/
 +    end
 +
 +    it "should fail when a required face option is not provided" do
 +      face = Puppet::Interface.new(:required_face_option, '0.0.1') do
 +        option('--foo') { required }
 +        action(:bar) { when_invoked { } }
 +      end
 +      expect { face.bar }.to raise_error ArgumentError, /missing required options \(foo\)/
 +    end
    end
  
    context "with action decorators" do
@@@ -371,4 -348,13 +371,13 @@@
        end
      end
    end
+ 
+   it_should_behave_like "documentation on faces" do
+     subject do
+       face = Puppet::Interface.new(:action_documentation, '0.0.1') do
+         action :documentation do end
+       end
+       face.get_action(:documentation)
+     end
+   end
  end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list