summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/option_manager.rb
diff options
context:
space:
mode:
authorPieter van de Bruggen <pieter@puppetlabs.com>2011-04-29 12:18:12 -0700
committerPieter van de Bruggen <pieter@puppetlabs.com>2011-04-29 12:25:46 -0700
commit207deae2dc06ca439e3b5ee9b044221a1c2899bb (patch)
tree3dcbc0c601dd7757fb0a865cc222ac97ded8b0d2 /lib/puppet/interface/option_manager.rb
parent1aaf5fdc51e165c7d0f377450016cd4fb3767c02 (diff)
downloadpuppet-207deae2dc06ca439e3b5ee9b044221a1c2899bb.tar.gz
puppet-207deae2dc06ca439e3b5ee9b044221a1c2899bb.tar.xz
puppet-207deae2dc06ca439e3b5ee9b044221a1c2899bb.zip
(#7289) Specify order for option decorations.
`before_action` decorations should always resolve in resolution order from most general (inherited from furthest away) to most specific (declared on the instance), and should always execute Face-level option decorations before action-level option decorations. `after_action` decorations should execute in the opposite order. Reviewed-By: Daniel Pittman
Diffstat (limited to 'lib/puppet/interface/option_manager.rb')
-rw-r--r--lib/puppet/interface/option_manager.rb29
1 files changed, 20 insertions, 9 deletions
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