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


The following commit has been merged in the experimental branch:
commit cec3b6e2627ea2340e46c2e498f4d41522140094
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Mon Apr 4 11:19:26 2011 -0700

    (#6749) Extract the action from the arguments cleanly.
    
    This adds a test to verify that we are correctly removing the action name from
    the set of arguments passed to the string action, then cleans up the previous
    code so we don't need to mutilate the command line arguments: we can just
    extract it from the resultant set of information.
    
    Reviewed-By: Nick Lewis <nick at puppetlabs.com>

diff --git a/lib/puppet/application/string_base.rb b/lib/puppet/application/string_base.rb
index a082ba0..8284a31 100644
--- a/lib/puppet/application/string_base.rb
+++ b/lib/puppet/application/string_base.rb
@@ -84,7 +84,6 @@ class Puppet::Application::StringBase < Puppet::Application
           raise ArgumentError, "#{@string} does not have an #{item.inspect} action!"
         end
         @action = action
-        command_line.args.delete_at(index)
       end
     end
 
@@ -105,7 +104,12 @@ class Puppet::Application::StringBase < Puppet::Application
     # action to read in the options.  This replaces the older model where we
     # would invoke the action with options set as global state in the
     # interface object.  --daniel 2011-03-28
-    @arguments = command_line.args
+    #
+    # Note: because of our definition of where the action is set, we end up
+    # with it *always* being the first word of the remaining set of command
+    # line arguments.  So, strip that off when we construct the arguments to
+    # pass down to the string action. --daniel 2011-04-04
+    @arguments = command_line.args[1, -1] || []
     @arguments << options
   end
 
diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb
index 7f06c05..5cfb835 100755
--- a/spec/unit/application/string_base_spec.rb
+++ b/spec/unit/application/string_base_spec.rb
@@ -115,6 +115,14 @@ describe Puppet::Application::StringBase do
     end
   end
 
+  describe "#setup" do
+    it "should remove the action name from the arguments" do
+      app.command_line.stubs(:args).returns %w{--mandatory --bar foo}
+      app.preinit and app.parse_options and app.setup
+      app.arguments.should == [{ :mandatory => "--bar" }]
+    end
+  end
+
   describe "#main" do
     before do
       app.string    = Puppet::String[:basetest, '0.0.1']

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list