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.



100
101
102
103
# File 'lib/puppet/util/command_line.rb', line 100

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.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/puppet/util/command_line.rb', line 105

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, 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.
  #
  if @subcommand_name != 'master' and @subcommand_name != 'agent'
    if configured_environment = Puppet.lookup(:environments).get(Puppet[:environment])
      configured_environment.each_plugin_directory do |dir|
        $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
      end

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

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