From: Daniel Pittman <[email protected]>

Previously, when the command line was empty we would try and invoke an empty
method; this was less helpful than telling people what they could actually do,
so we adapt our code to do precisely that.

Paired-With: Jesse Wolfe <[email protected]>
Signed-off-by: Daniel Pittman <[email protected]>
---
 lib/puppet/application/cert.rb     |    8 +++++++-
 spec/unit/application/cert_spec.rb |   10 ++++++++++
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index c8aad18..ee59b7e 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -89,7 +89,13 @@ class Puppet::Application::Cert < Puppet::Application
   def parse_options
     # handle the bareword subcommand pattern.
     result = super
-    self.subcommand ||= self.command_line.args.shift
+    unless self.subcommand then
+      if sub = self.command_line.args.shift then
+        self.subcommand = sub
+      else
+        help
+      end
+    end
     result
   end
 end
diff --git a/spec/unit/application/cert_spec.rb 
b/spec/unit/application/cert_spec.rb
index 2f57d07..b325791 100755
--- a/spec/unit/application/cert_spec.rb
+++ b/spec/unit/application/cert_spec.rb
@@ -189,6 +189,16 @@ describe Puppet::Application::Cert do
       @cert_app.ca = @ca
     end
 
+    it "should not fail when no command is given" 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|
-- 
1.7.4.1

-- 
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.

Reply via email to