diff options
| author | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-29 13:36:36 -0700 |
|---|---|---|
| committer | Pieter van de Bruggen <pieter@puppetlabs.com> | 2011-04-29 13:36:36 -0700 |
| commit | 07efb2463dfc4720df3996bb2f7a80844914f0da (patch) | |
| tree | 163ad35431200ac28e58183d30362dd77de97be6 /lib/puppet/interface | |
| parent | 97ae812f0a67ef01daed4e9220981e2bc7c70603 (diff) | |
| parent | 207deae2dc06ca439e3b5ee9b044221a1c2899bb (diff) | |
| download | puppet-07efb2463dfc4720df3996bb2f7a80844914f0da.tar.gz puppet-07efb2463dfc4720df3996bb2f7a80844914f0da.tar.xz puppet-07efb2463dfc4720df3996bb2f7a80844914f0da.zip | |
Merge branch 'tickets/2.7.x/7289' into 2.7.x
Diffstat (limited to 'lib/puppet/interface')
| -rw-r--r-- | lib/puppet/interface/action.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/interface/option_manager.rb | 29 |
2 files changed, 29 insertions, 14 deletions
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index b842c2831..0dbdd57bb 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -18,7 +18,10 @@ class Puppet::Interface::Action attrs.each do |k, v| send("#{k}=", v) end - @options = {} + # @options collects the added options in the order they're declared. + # @options_hash collects the options keyed by alias for quick lookups. + @options = [] + @options_hash = {} @when_rendering = {} end @@ -232,22 +235,23 @@ WRAPPER end option.aliases.each do |name| - @options[name] = option + @options << name + @options_hash[name] = option end option end def option?(name) - @options.include? name.to_sym + @options_hash.include? name.to_sym end def options - (@options.keys + @face.options).sort + @face.options + @options end def get_option(name, with_inherited_options = true) - option = @options[name.to_sym] + option = @options_hash[name.to_sym] if option.nil? and with_inherited_options option = @face.get_option(name) end diff --git a/lib/puppet/interface/option_manager.rb b/lib/puppet/interface/option_manager.rb index d42359c07..326a91d92 100644 --- a/lib/puppet/interface/option_manager.rb +++ b/lib/puppet/interface/option_manager.rb @@ -8,6 +8,11 @@ module Puppet::Interface::OptionManager end def add_option(option) + # @options collects the added options in the order they're declared. + # @options_hash collects the options keyed by alias for quick lookups. + @options ||= [] + @options_hash ||= {} + option.aliases.each do |name| if conflict = get_option(name) then raise ArgumentError, "Option #{option} conflicts with existing option #{conflict}" @@ -21,25 +26,30 @@ module Puppet::Interface::OptionManager end end - option.aliases.each { |name| @options[name] = option } - option + option.aliases.each do |name| + @options << name + @options_hash[name] = option + end + + return option end def options - @options ||= {} - result = @options.keys + result = (@options ||= []) if self.is_a?(Class) and superclass.respond_to?(:options) - result += superclass.options + result = superclass.options + result elsif self.class.respond_to?(:options) - result += self.class.options + result = self.class.options + result end - result.sort + + return result end def get_option(name, with_inherited_options = true) - @options ||= {} - result = @options[name.to_sym] + @options_hash ||= {} + + result = @options_hash[name.to_sym] if result.nil? and with_inherited_options then if self.is_a?(Class) and superclass.respond_to?(:get_option) result = superclass.get_option(name) @@ -47,6 +57,7 @@ module Puppet::Interface::OptionManager result = self.class.get_option(name) end end + return result end |
