summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2010-09-22 12:26:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-09-22 21:11:32 -0700
commit4798df328526d08644ea40161dcd2c88799b57db (patch)
tree4c9dc0e18887443d195300e98fe6de4f16fc51ae /lib
parent99c1019e1d3402ec8e476dc859d5aaef82ec4f69 (diff)
downloadpuppet-4798df328526d08644ea40161dcd2c88799b57db.tar.gz
puppet-4798df328526d08644ea40161dcd2c88799b57db.tar.xz
puppet-4798df328526d08644ea40161dcd2c88799b57db.zip
Fixes #4822 -- Puppet doc -o option broken
The global "-o" option ("--onetime") was overriding the application-specific option "-o" because global options were being sent to the OptionParser after application-specific options. Modified the order in which options are sent to the OptionParser to have the correct behavior. Also merged together the two methods that were applying options so that the order is more explicit.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application.rb38
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'"