From a1db58528f2baf7867202058d80e66f23fb447e0 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 20:52:52 -0700 Subject: maint: fix gratuitous whitespace in the code. We had some stray spacing between variables and the '=' sign from when there was another variable in place; it got deleted, but the code wasn't closed up. Reviewed-By: Max Martin --- lib/puppet/application/face_base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 9da48af55..fabe71896 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -92,8 +92,8 @@ class Puppet::Application::FaceBase < Puppet::Application # 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::Face[@type, :current] + @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym + @face = Puppet::Face[@type, :current] # Now, walk the command line and identify the action. We skip over # arguments based on introspecting the action and all, and find the first -- cgit From 379b46d4b9e2a57f954ff178956ca6850c3c56f7 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Tue, 19 Apr 2011 21:08:05 -0700 Subject: (#7116) Handle application-level options in parse_options We hid another layer of per-application option in the class backing the application, which wasn't correctly handled in the parse_options method. They are now found and handled, so that global flags like --debug work as expected on the left of the action, not just the right. Reviewed-By: Max Martin --- lib/puppet/application/face_base.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/puppet/application') diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index fabe71896..7bebd18bb 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -122,6 +122,8 @@ class Puppet::Application::FaceBase < Puppet::Application # a mandatory argument. --daniel 2011-04-05 index += 1 # ...so skip the argument. end + elsif option = find_application_argument(item) then + index += 1 if (option[:argument] and option[:optional]) else raise OptionParser::InvalidOption.new(item.sub(/=.*$/, '')) end @@ -158,6 +160,21 @@ class Puppet::Application::FaceBase < Puppet::Application return nil # nothing found. end + def find_application_argument(item) + self.class.option_parser_commands.each do |options, function| + options.each do |option| + next unless option =~ /^-/ + pattern = /^#{option.sub('[no-]', '').sub(/[ =].*$/, '')}(?:[ =].*)?$/ + next unless pattern.match(item) + return { + :argument => option =~ /[ =]/, + :optional => option =~ /[ =]\[/ + } + end + end + return nil # not found + end + def setup Puppet::Util::Log.newdestination :console -- cgit