module Puppet::Interface::OptionManager
This class is not actually public API, but the method {Puppet::Interface::OptionManager#option option} is public when used as part of the Faces DSL (i.e. from within a {Puppet::Interface.define define} block). @api public
Public Instance Methods
add_option(option)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 49 def add_option(option) 50 # @options collects the added options in the order they're declared. 51 # @options_hash collects the options keyed by alias for quick lookups. 52 @options ||= [] 53 @options_hash ||= {} 54 55 option.aliases.each do |name| 56 conflict = get_option(name) 57 if conflict 58 raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict}") % 59 { option: option, conflict: conflict } 60 end 61 62 actions.each do |action| 63 action = get_action(action) 64 conflict = action.get_option(name) 65 if conflict 66 raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict} on %{action}") % 67 { option: option, conflict: conflict, action: action } 68 end 69 end 70 end 71 72 @options << option.name 73 74 option.aliases.each do |name| 75 @options_hash[name] = option 76 end 77 78 return option 79 end
all_display_global_options()
click to toggle source
# File lib/puppet/interface/option_manager.rb 23 def all_display_global_options 24 walk_inheritance_tree(@display_global_options, :all_display_global_options) 25 end
display_global_options(*args)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 9 def display_global_options(*args) 10 @display_global_options ||= [] 11 [args].flatten.each do |refopt| 12 unless Puppet.settings.include?(refopt) 13 #TRANSLATORS 'Puppet.settings' references to the Puppet settings options and should not be translated 14 raise ArgumentError, _("Global option %{option} does not exist in Puppet.settings") % { option: refopt } 15 end 16 @display_global_options << refopt if refopt 17 end 18 @display_global_options.uniq! 19 @display_global_options 20 end
Also aliased as: display_global_option
get_option(name, with_inherited_options = true)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 87 def get_option(name, with_inherited_options = true) 88 @options_hash ||= {} 89 90 result = @options_hash[name.to_sym] 91 if result.nil? and with_inherited_options then 92 if self.is_a?(Class) and superclass.respond_to?(:get_option) 93 result = superclass.get_option(name) 94 elsif self.class.respond_to?(:get_option) 95 result = self.class.get_option(name) 96 end 97 end 98 99 return result 100 end
option(*declaration, &block)
click to toggle source
Declare that this app can take a specific option, and provide the code to do so. See {Puppet::Interface::ActionBuilder#option} for details.
@api public @dsl Faces
# File lib/puppet/interface/option_manager.rb 44 def option(*declaration, &block) 45 add_option Puppet::Interface::OptionBuilder.build(self, *declaration, &block) 46 end
option?(name)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 103 def option?(name) 104 options.include? name.to_sym 105 end
options()
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 82 def options 83 walk_inheritance_tree(@options, :options) 84 end
walk_inheritance_tree(start, sym)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 28 def walk_inheritance_tree(start, sym) 29 result = (start || []) 30 if self.is_a?(Class) and superclass.respond_to?(sym) 31 result = superclass.send(sym) + result 32 elsif self.class.respond_to?(sym) 33 result = self.class.send(sym) + result 34 end 35 return result 36 end