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 50 def add_option(option) 51 # @options collects the added options in the order they're declared. 52 # @options_hash collects the options keyed by alias for quick lookups. 53 @options ||= [] 54 @options_hash ||= {} 55 56 option.aliases.each do |name| 57 conflict = get_option(name) 58 if conflict 59 raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict}") % 60 { option: option, conflict: conflict } 61 end 62 63 actions.each do |action| 64 action = get_action(action) 65 conflict = action.get_option(name) 66 if conflict 67 raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict} on %{action}") % 68 { option: option, conflict: conflict, action: action } 69 end 70 end 71 end 72 73 @options << option.name 74 75 option.aliases.each do |name| 76 @options_hash[name] = option 77 end 78 79 return option 80 end
all_display_global_options()
click to toggle source
# File lib/puppet/interface/option_manager.rb 24 def all_display_global_options 25 walk_inheritance_tree(@display_global_options, :all_display_global_options) 26 end
display_global_options(*args)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 10 def display_global_options(*args) 11 @display_global_options ||= [] 12 [args].flatten.each do |refopt| 13 unless Puppet.settings.include?(refopt) 14 #TRANSLATORS 'Puppet.settings' references to the Puppet settings options and should not be translated 15 raise ArgumentError, _("Global option %{option} does not exist in Puppet.settings") % { option: refopt } 16 end 17 @display_global_options << refopt if refopt 18 end 19 @display_global_options.uniq! 20 @display_global_options 21 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 88 def get_option(name, with_inherited_options = true) 89 @options_hash ||= {} 90 91 result = @options_hash[name.to_sym] 92 if result.nil? and with_inherited_options then 93 if self.is_a?(Class) and superclass.respond_to?(:get_option) 94 result = superclass.get_option(name) 95 elsif self.class.respond_to?(:get_option) 96 result = self.class.get_option(name) 97 end 98 end 99 100 return result 101 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 45 def option(*declaration, &block) 46 add_option Puppet::Interface::OptionBuilder.build(self, *declaration, &block) 47 end
option?(name)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 104 def option?(name) 105 options.include? name.to_sym 106 end
options()
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 83 def options 84 walk_inheritance_tree(@options, :options) 85 end
walk_inheritance_tree(start, sym)
click to toggle source
@api private
# File lib/puppet/interface/option_manager.rb 29 def walk_inheritance_tree(start, sym) 30 result = (start || []) 31 if self.is_a?(Class) and superclass.respond_to?(sym) 32 result = superclass.send(sym) + result 33 elsif self.class.respond_to?(sym) 34 result = self.class.send(sym) + result 35 end 36 return result 37 end