From 7228f580a22cc13dc66a93d81bf57a5bad80a73f Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 11 Apr 2011 11:42:25 -0700 Subject: maint: finish transition of application help to return strings. Jesse made a change, in e1191f33defcaffec5900c7122a89ca75d3a9673, to transition from printing and exiting in the help method up to returning the help data to the caller. This was part of eliminating rdoc usage from the display of help to the user. The cert application was missed, and still used the legacy "print and exit" model; this cleans that up so it matches the rest of the code. Paired-With: Matt Robinson --- lib/puppet/application/cert.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb index cbd6fd610..c08775380 100644 --- a/lib/puppet/application/cert.rb +++ b/lib/puppet/application/cert.rb @@ -48,7 +48,7 @@ class Puppet::Application::Cert < Puppet::Application end def help - puts <<-HELP + <<-HELP puppet-cert(8) -- Manage certificates and requests ======== @@ -166,7 +166,6 @@ COPYRIGHT Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License HELP - exit end def main -- cgit From 1b4d7a51d10b217c7f67f3876242fff6dc694faa Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 4 Apr 2011 16:46:09 -0700 Subject: (#6962) Create the basic shape of the help face. This implements the basic help face, along with the start of the support structures; we include the basic application, and the default help action that just emits a listing of faces and other discovered stuff... Reviewed-By: Matt Robinson --- lib/puppet/application/help.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/puppet/application/help.rb (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb new file mode 100644 index 000000000..69905af27 --- /dev/null +++ b/lib/puppet/application/help.rb @@ -0,0 +1,7 @@ +require 'puppet/application/faces_base' + +class Puppet::Application::Help < Puppet::Application::FacesBase + def render(result) + puts result.join("\n") + end +end -- cgit From 26db6456d22b95486646ae5b8b001acb2051c4da Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 11 Apr 2011 11:26:25 -0700 Subject: (#6962) render prints the rval; fix help subcommand. The face application base uses render to transform the returned object to a form where #to_s produces the output intended for the end user; we were actually printing in the method instead, leading to an extraneous 'nil' at the end of the output... Paired-With: Matt Robinson --- lib/puppet/application/help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb index 69905af27..b3666f12d 100644 --- a/lib/puppet/application/help.rb +++ b/lib/puppet/application/help.rb @@ -2,6 +2,6 @@ require 'puppet/application/faces_base' class Puppet::Application::Help < Puppet::Application::FacesBase def render(result) - puts result.join("\n") + result.join("\n") end end -- cgit From 2a87f410eae84a0a7c4f39d9c1ef742c3e7ba8fc Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 11 Apr 2011 16:43:56 -0700 Subject: (#6962) Override 'render' in help to just return the string. The default behaviour is to serialize the result somehow, defaulting to displayed, render should be a no-op. This means overriding the parent method. Paired-With: Matt Robinson --- lib/puppet/application/help.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb index b3666f12d..fd8818db0 100644 --- a/lib/puppet/application/help.rb +++ b/lib/puppet/application/help.rb @@ -1,7 +1,8 @@ +# -*- coding: utf-8 -*- require 'puppet/application/faces_base' class Puppet::Application::Help < Puppet::Application::FacesBase - def render(result) - result.join("\n") - end + # Meh. Disable the default behaviour, which is to inspect the + # string and return that – not so helpful. --daniel 2011-04-11 + def render(result) result end end -- cgit From 7b4d9367b391f75983868046d30928ebc8411f50 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 12 Apr 2011 11:45:05 -0700 Subject: (#6962) Move option handling into #parse_options, not #preinit. Logically, the extra work around option parsing for faces belongs in the application parse_options method, not hidden in the step before. This commit moves that to the right place and fixes the fallout from that strange early design decision. Along the way we unify error reporting for invalid options so that all the code paths result in the same externally detected failures. Reviewed-By: Matt Robinson --- lib/puppet/application/faces_base.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/faces_base.rb b/lib/puppet/application/faces_base.rb index 288b50048..f1b77f285 100644 --- a/lib/puppet/application/faces_base.rb +++ b/lib/puppet/application/faces_base.rb @@ -1,5 +1,6 @@ require 'puppet/application' require 'puppet/faces' +require 'optparse' class Puppet::Application::FacesBase < Puppet::Application should_parse_config @@ -50,11 +51,13 @@ class Puppet::Application::FacesBase < Puppet::Application $stderr.puts "Cancelling Face" exit(0) end + end + def parse_options # We need to parse enough of the command line out early, to identify what # the action is, so that we can obtain the full set of options to parse. - # TODO: These should be configurable versions, through a global + # REVISIT: These should be configurable versions, through a global # '--version' option, but we don't implement that yet... --daniel 2011-03-29 @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym @face = Puppet::Faces[@type, :current] @@ -88,25 +91,30 @@ class Puppet::Application::FacesBase < Puppet::Application index += 1 # ...so skip the argument. end else - raise ArgumentError, "Unknown option #{item.sub(/=.*$/, '').inspect}" + raise OptionParser::InvalidOption.new(item.sub(/=.*$/, '')) end else action = @face.get_action(item.to_sym) if action.nil? then - raise ArgumentError, "#{@face} does not have an #{item.inspect} action!" + raise OptionParser::InvalidArgument.new("#{@face} does not have an #{item} action") end @action = action end end - @action or raise ArgumentError, "No action given on the command line!" + unless @action + raise OptionParser::MissingArgument.new("No action given on the command line") + end - # Finally, we can interact with the default option code to build behaviour + # Now we can interact with the default option code to build behaviour # around the full set of options we now know we support. @action.options.each do |option| option = @action.get_option(option) # make it the object. self.class.option(*option.optparse) # ...and make the CLI parse it. end + + # ...and invoke our parent to parse all the command line options. + super end def find_global_settings_argument(item) -- cgit