+1 On Mon, May 24, 2010 at 5:10 PM, Jesse Wolfe <[email protected]> wrote: > This patch allows the puppet single-executable to invoke external, > hyphenated subcommands, much like how git does. > > Signed-off-by: Jesse Wolfe <[email protected]> > --- > lib/puppet/util.rb | 1 + > lib/puppet/util/command_line.rb | 15 ++++++++++++++- > spec/unit/util/command_line.rb | 22 ++++++++++++++++++++++ > 3 files changed, 37 insertions(+), 1 deletions(-) > > diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb > index e06d6e6..1069552 100644 > --- a/lib/puppet/util.rb > +++ b/lib/puppet/util.rb > @@ -6,6 +6,7 @@ require 'puppet/external/lock' > > module Puppet > # A command failed to execute. > + require 'puppet/error' > class ExecutionFailure < Puppet::Error > end > module Util > diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb > index e665698..9a676fa 100644 > --- a/lib/puppet/util/command_line.rb > +++ b/lib/puppet/util/command_line.rb > @@ -77,10 +77,23 @@ module Puppet > require File.join(self.class.appdir, 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 e20f51a..bd80823 100644 > --- a/spec/unit/util/command_line.rb > +++ b/spec/unit/util/command_line.rb > @@ -110,4 +110,26 @@ describe Puppet::Util::CommandLine do > end > 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 > -- > 1.7.0.4 > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > >
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
