summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-21 19:04:39 -0700
committerMax Martin <max@puppetlabs.com>2011-04-21 19:04:39 -0700
commit25593abbb044aca86c71cd60e91665eca0ce1bd1 (patch)
treed8703468b9b598c196348b748fbe47333b31a745 /lib/puppet/application
parent01f610bb223b435dc52f491260af3ea002930102 (diff)
parente4b31b411a4b3d7cce7f45197491eebc36d047aa (diff)
Merge branch 'next'
* next: (#6928) Don't blow up when the method is undefined... (#6928) backport Symbol#to_proc for Ruby < 1.8.7 (#7183) Implement "invisible glob" version matching for faces maint: better disabling of Signal#trap in our tests. maint: more robust listing of valid faces. maint: clean up testing code a fraction... maint: better error report for a missing version of a face. maint: handle face clear/reset sanely in the interface spec. maint: stop stubbing log level setting. Move tests from Puppet-acceptance repo (#7116) Handle application-level options in parse_options maint: fix gratuitous whitespace in the code. maint: remove redundant context from the test. (#7062) better argument handling in the action wrapper methods maint: move method comments outside the comment. Fixed #7166 - Replaced deprecated stomp "send" method with "publish" maint: Remove unused faces code
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/face_base.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb
index 9da48af55..7bebd18bb 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
@@ -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