[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:35:02 UTC 2010


The following commit has been merged in the upstream branch:
commit 3696d951f70f5b94b49619dfbc57138d5241bbb8
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Mon May 24 17:04:17 2010 -0700

    [#3865] External subcommands
    
    This patch allows the puppet single-executable to invoke external,
    hyphenated subcommands, much like how git does.

diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 8a010bb..8c8eb91 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -51,10 +51,23 @@ module Puppet
                     require_application subcommand_name
                     Puppet::Application.find(subcommand_name).new(self).run
                 else
-                    abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
+                    unless execute_external_subcommand
+                        abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
+                    end
                 end
             end
 
+            def execute_external_subcommand
+                    external_command = "puppet-#{subcommand_name}"
+
+                    require 'puppet/util'
+                    path_to_subcommand = Puppet::Util.binary( external_command )
+                    return false unless path_to_subcommand
+
+                    system( path_to_subcommand, *args )
+                    true
+            end
+
             def legacy_executable_name
                 LegacyName[ subcommand_name ]
             end
diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb
index 7413e57..31b2d1b 100644
--- a/spec/unit/util/command_line.rb
+++ b/spec/unit/util/command_line.rb
@@ -83,4 +83,26 @@ describe Puppet::Util::CommandLine do
         command_line.legacy_executable_name.should == "puppetmasterd"
     end
 
+    describe "when the subcommand is not implemented" do
+        it "should find and invoke an executable with a hyphenated name" do
+            commandline = Puppet::Util::CommandLine.new("puppet", ['whatever', 'argument'], @tty)
+            Puppet::Util.expects(:binary).with('puppet-whatever').returns('/dev/null/puppet-whatever')
+            commandline.expects(:system).with('/dev/null/puppet-whatever', 'argument')
+
+            commandline.execute
+        end
+
+        describe "and an external implementation cannot be found" do
+            it "should abort and show the usage message" do
+                commandline = Puppet::Util::CommandLine.new("puppet", ['whatever', 'argument'], @tty)
+                Puppet::Util.expects(:binary).with('puppet-whatever').returns(nil)
+                commandline.expects(:system).never
+
+                commandline.expects(:usage_message).returns("the usage message")
+                commandline.expects(:abort).with{|x| x =~ /the usage message/}.raises("stubbed abort")
+
+                lambda{ commandline.execute }.should raise_error('stubbed abort')
+            end
+        end
+    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list