Module: Puppet::Interface::OptionManager

Included in:
Puppet::Interface, Puppet::Interface
Defined in:
lib/puppet/interface/option_manager.rb

Overview

This class is not actually public API, but the method option is public when used as part of the Faces DSL (i.e. from within a define block).

Instance Method Summary collapse

Instance Method Details

#add_option(option) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/puppet/interface/option_manager.rb', line 50

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|
    conflict = get_option(name)
    if conflict
      raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict}") %
          { option: option, conflict: conflict }
    end

    actions.each do |action|
      action = get_action(action)
      conflict = action.get_option(name)
      if conflict
        raise ArgumentError, _("Option %{option} conflicts with existing option %{conflict} on %{action}") %
            { option: option, conflict: conflict, action: action }
      end
    end
  end

  @options << option.name

  option.aliases.each do |name|
    @options_hash[name] = option
  end

  return option
end

#all_display_global_optionsObject



24
25
26
# File 'lib/puppet/interface/option_manager.rb', line 24

def all_display_global_options
  walk_inheritance_tree(@display_global_options, :all_display_global_options)
end

#display_global_options(*args) ⇒ Object Also known as: display_global_option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppet/interface/option_manager.rb', line 10

def display_global_options(*args)
  @display_global_options ||= []
  [args].flatten.each do |refopt|
    unless Puppet.settings.include?(refopt)
      #TRANSLATORS 'Puppet.settings' references to the Puppet settings options and should not be translated
      raise ArgumentError, _("Global option %{option} does not exist in Puppet.settings") % { option: refopt }
    end
    @display_global_options << refopt if refopt
  end
  @display_global_options.uniq!
  @display_global_options
end

#get_option(name, with_inherited_options = true) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/puppet/interface/option_manager.rb', line 88

def get_option(name, with_inherited_options = true)
  @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)
    elsif self.class.respond_to?(:get_option)
      result = self.class.get_option(name)
    end
  end

  return result
end

#option(*declaration, &block) ⇒ Object

Declare that this app can take a specific option, and provide the code to do so. See ActionBuilder#option for details.



45
46
47
# File 'lib/puppet/interface/option_manager.rb', line 45

def option(*declaration, &block)
  add_option Puppet::Interface::OptionBuilder.build(self, *declaration, &block)
end

#option?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


104
105
106
# File 'lib/puppet/interface/option_manager.rb', line 104

def option?(name)
  options.include? name.to_sym
end

#optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



83
84
85
# File 'lib/puppet/interface/option_manager.rb', line 83

def options
  walk_inheritance_tree(@options, :options)
end

#walk_inheritance_tree(start, sym) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
36
37
# File 'lib/puppet/interface/option_manager.rb', line 29

def walk_inheritance_tree(start, sym)
  result = (start || [])
  if self.is_a?(Class) and superclass.respond_to?(sym)
    result = superclass.send(sym) + result
  elsif self.class.respond_to?(sym)
    result = self.class.send(sym) + result
  end
  return result
end