diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-11 23:09:18 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-12 16:12:09 -0700 |
| commit | 826d5dff531eb624fef91a7298932e9ec5a46231 (patch) | |
| tree | ee4b9ad747e36232c1693982d513711a2b066122 | |
| parent | 9496067f5644972def823cf8c3318aca137b86fe (diff) | |
(#6962) delegate global usage to the help face.
The global --help handler (also invoked when puppet is run without any other
command line options at all) used to spit out a brief and generally not so
helpful message.
Now that we have a help face that can provide the same information in a much
more user-friendly form, we should delegate the function to that when
required.
Reviewed-By: Matt Robinson <matt@puppetlabs.com>
| -rw-r--r-- | lib/puppet/util/command_line.rb | 23 | ||||
| -rwxr-xr-x | spec/unit/application/cert_spec.rb | 14 | ||||
| -rwxr-xr-x | spec/unit/util/command_line_spec.rb | 7 |
3 files changed, 18 insertions, 26 deletions
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index 2891030df..674927842 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -49,26 +49,29 @@ module Puppet self.class.available_subcommands end - def usage_message - usage = "Usage: puppet command <space separated arguments>" - available = "Available commands are: #{available_subcommands.sort.join(', ')}" - [usage, available].join("\n") - end - def require_application(application) require File.join(appdir, application) end def execute - if subcommand_name.nil? - puts usage_message - elsif available_subcommands.include?(subcommand_name) #subcommand + if subcommand_name and available_subcommands.include?(subcommand_name) then require_application subcommand_name app = Puppet::Application.find(subcommand_name).new(self) Puppet::Plugins.on_application_initialization(:appliation_object => self) app.run + elsif execute_external_subcommand then + # Logically, we shouldn't get here, but we do, so whatever. We just + # return to the caller. How strange we are. --daniel 2011-04-11 else - abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}" unless execute_external_subcommand + unless subcommand_name.nil? then + puts "Error: Unknown Puppet subcommand #{subcommand_name}.\n" + end + + # Doing this at the top of the file is natural, but causes puppet.rb + # to load too early, which causes things to break. This is a nasty + # thing, found in #7065. --daniel 2011-04-11 + require 'puppet/faces/help' + puts Puppet::Faces[:help, :current].help end end diff --git a/spec/unit/application/cert_spec.rb b/spec/unit/application/cert_spec.rb index 5b25ab7b8..a1b5eb19a 100755 --- a/spec/unit/application/cert_spec.rb +++ b/spec/unit/application/cert_spec.rb @@ -1,7 +1,5 @@ -#!/usr/bin/env ruby - +#!/usr/bin/env rspec require 'spec_helper' - require 'puppet/application/cert' describe Puppet::Application::Cert do @@ -189,16 +187,6 @@ describe Puppet::Application::Cert do @cert_app.ca = @ca end - it "should SystemExit after printing help message" do - # Make the help method silent for testing; this is a bit nasty, but we - # can't identify a cleaner method. Help welcome. --daniel 2011-02-22 - Puppet.features.stubs(:usage?).returns(false) - @cert_app.stubs(:puts) - - @cert_app.command_line.stubs(:args).returns([]) - expect { @cert_app.parse_options }.should raise_error SystemExit - end - %w{list revoke generate sign print verify fingerprint}.each do |cmd| short = cmd[0,1] [cmd, "--#{cmd}", "-#{short}"].each do |option| diff --git a/spec/unit/util/command_line_spec.rb b/spec/unit/util/command_line_spec.rb index c5c6e5f3e..6cf90475b 100755 --- a/spec/unit/util/command_line_spec.rb +++ b/spec/unit/util/command_line_spec.rb @@ -99,10 +99,11 @@ describe Puppet::Util::CommandLine do Puppet::Util.expects(:which).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") + text = Puppet::Faces[:help, :current].help + commandline.expects(:puts).with { |x| x =~ /Unknown Puppet subcommand/ } + commandline.expects(:puts).with text - lambda{ commandline.execute }.should raise_error('stubbed abort') + commandline.execute end end end |
