diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-10-04 12:22:44 -0700 |
---|---|---|
committer | Jesse Wolfe <jes5199@gmail.com> | 2010-10-04 12:22:47 -0700 |
commit | 1a00c07971c4297bce1b3e0edee3b6b3399e17bb (patch) | |
tree | 0a8b1f1be1eddcb31e1b0ff7d69dbb60bd1c7e81 /lib/puppet/application.rb | |
parent | d43f7996b93c394df0bd0994ae7298fb35ad2c5e (diff) | |
parent | 66cf3a925b4b6d9b40cbdf95f2be6575bb05a881 (diff) | |
download | puppet-1a00c07971c4297bce1b3e0edee3b6b3399e17bb.tar.gz puppet-1a00c07971c4297bce1b3e0edee3b6b3399e17bb.tar.xz puppet-1a00c07971c4297bce1b3e0edee3b6b3399e17bb.zip |
Partial merge to 2.6.2rc1 : Merge commit '66cf3a9' into next
There are test failures in commits following this one.
Diffstat (limited to 'lib/puppet/application.rb')
-rw-r--r-- | lib/puppet/application.rb | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 2fec38bf2..f0159a65d 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -254,19 +254,6 @@ class Application def preinit end - def option_parser - return @option_parser if defined?(@option_parser) - - @option_parser = OptionParser.new(self.class.banner) - - self.class.option_parser_commands.each do |options, fname| - @option_parser.on(*options) do |value| - self.send(fname, value) - end - end - @option_parser - end - def initialize(command_line = nil) require 'puppet/util/command_line' @command_line = command_line || Puppet::Util::CommandLine.new @@ -323,20 +310,29 @@ class Application end def parse_options - # get all puppet options - optparse_opt = [] - optparse_opt = Puppet.settings.optparse_addargs(optparse_opt) + # Create an option parser + option_parser = OptionParser.new(self.class.banner) - # convert them to OptionParser format - optparse_opt.each do |option| - self.option_parser.on(*option) do |arg| + # Add all global options to it. + Puppet.settings.optparse_addargs([]).each do |option| + option_parser.on(*option) do |arg| handlearg(option[0], arg) end end - # scan command line argument + # Add options that are local to this application, which were + # created using the "option()" metaprogramming method. If there + # are any conflicts, this application's options will be favored. + self.class.option_parser_commands.each do |options, fname| + option_parser.on(*options) do |value| + # Call the method that "option()" created. + self.send(fname, value) + end + end + + # scan command line. begin - self.option_parser.parse!(self.command_line.args) + option_parser.parse!(self.command_line.args) rescue OptionParser::ParseError => detail $stderr.puts detail $stderr.puts "Try 'puppet #{command_line.subcommand_name} --help'" |