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


The following commit has been merged in the experimental branch:
commit 379b46d4b9e2a57f954ff178956ca6850c3c56f7
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Tue Apr 19 21:08:05 2011 -0700

    (#7116) Handle application-level options in parse_options
    
    We hid another layer of per-application option in the class backing the
    application, which wasn't correctly handled in the parse_options method.
    
    They are now found and handled, so that global flags like --debug work as
    expected on the left of the action, not just the right.
    
    Reviewed-By: Max Martin <max at puppetlabs.com>

diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb
index fabe718..7bebd18 100644
--- a/lib/puppet/application/face_base.rb
+++ b/lib/puppet/application/face_base.rb
@@ -122,6 +122,8 @@ class Puppet::Application::FaceBase < Puppet::Application
             # a mandatory argument. --daniel 2011-04-05
             index += 1          # ...so skip the argument.
           end
+        elsif option = find_application_argument(item) then
+          index += 1 if (option[:argument] and option[:optional])
         else
           raise OptionParser::InvalidOption.new(item.sub(/=.*$/, ''))
         end
@@ -158,6 +160,21 @@ class Puppet::Application::FaceBase < Puppet::Application
     return nil                  # nothing found.
   end
 
+  def find_application_argument(item)
+    self.class.option_parser_commands.each do |options, function|
+      options.each do |option|
+        next unless option =~ /^-/
+        pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/
+        next unless pattern.match(item)
+        return {
+          :argument => option =~ /[ =]/,
+          :optional => option =~ /[ =]\[/
+        }
+      end
+    end
+    return nil                  # not found
+  end
+
   def setup
     Puppet::Util::Log.newdestination :console
 
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index 7dbe59f..f7c55c5 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -40,7 +40,7 @@ describe Puppet::Application::FaceBase do
       app.command_line.stubs(:args).returns %w{}
     end
 
-    context "with just an action" do
+    describe "with just an action" do
       before :all do
         # We have to stub Signal.trap to avoid a crazy mess where we take
         # over signal handling and make it impossible to cancel the test
@@ -160,6 +160,13 @@ describe Puppet::Application::FaceBase do
         Puppet[:syslogfacility].should == "user1"
       end
     end
+
+    it "should handle application-level options" do
+      app.command_line.stubs(:args).returns %w{help --verbose help}
+      app.preinit
+      app.parse_options
+      app.face.name.should == :basetest
+    end
   end
 
   describe "#setup" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list