Class: Puppet::Util::CommandLine::ApplicationSubcommand Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/command_line.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(subcommand_name, command_line) ⇒ ApplicationSubcommand

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 a new instance of ApplicationSubcommand.



110
111
112
113
# File 'lib/puppet/util/command_line.rb', line 110

def initialize(subcommand_name, command_line)
  @subcommand_name = subcommand_name
  @command_line = command_line
end

Instance Method Details

#runObject

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.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/puppet/util/command_line.rb', line 115

def run
  # For most applications, we want to be able to load code from the modulepath,
  # such as apply, describe, resource, and faces.
  # For agent and device in agent mode, we only want to load pluginsync'ed code from libdir.
  # For master, we shouldn't ever be loading per-environment code into the master's
  # ruby process, but that requires fixing (#17210, #12173, #8750). So for now
  # we try to restrict to only code that can be autoloaded from the node's
  # environment.

  # PUP-2114 - at this point in the bootstrapping process we do not
  # have an appropriate application-wide current_environment set.
  # If we cannot find the configured environment, which may not exist,
  # we do not attempt to add plugin directories to the load path.
  unless @subcommand_name == 'master' || @subcommand_name == 'agent' || (@subcommand_name == 'device' && (['--apply', '--facts', '--resource'] - @command_line.args).empty?)
    configured_environment = Puppet.lookup(:environments).get(Puppet[:environment])
    if configured_environment
      configured_environment.each_plugin_directory do |dir|
        $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
      end

      Puppet::ModuleTranslations.load_from_modulepath(configured_environment.modules)
      Puppet::ModuleTranslations.load_from_vardir(Puppet[:vardir])

      # Puppet requires Facter, which initializes its lookup paths. Reset Facter to
      # pickup the new $LOAD_PATH.
      Puppet.runtime[:facter].reset
    end
  end

  app = Puppet::Application.find(@subcommand_name).new(@command_line)
  app.run
end