summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-05-24 17:04:17 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit3696d951f70f5b94b49619dfbc57138d5241bbb8 (patch)
tree9032825792f576a84311d4025fea316bf3ae565d
parent0fc41aed7056e645f1d41a7ef6a00a34344dde38 (diff)
downloadpuppet-3696d951f70f5b94b49619dfbc57138d5241bbb8.tar.gz
[#3865] External subcommands
This patch allows the puppet single-executable to invoke external, hyphenated subcommands, much like how git does.
-rw-r--r--lib/puppet/util/command_line.rb15
-rw-r--r--spec/unit/util/command_line.rb22
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 8a010bb76..8c8eb91d5 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 7413e57d1..31b2d1b03 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