class Puppet::Util::CommandLine::ApplicationSubcommand

@api private

Public Class Methods

new(subcommand_name, command_line) click to toggle source
    # File lib/puppet/util/command_line.rb
109 def initialize(subcommand_name, command_line)
110   @subcommand_name = subcommand_name
111   @command_line = command_line
112 end

Public Instance Methods

run() click to toggle source
    # File lib/puppet/util/command_line.rb
114 def run
115   # For most applications, we want to be able to load code from the modulepath,
116   # such as apply, describe, resource, and faces.
117   # For agent and device in agent mode, we only want to load pluginsync'ed code from libdir.
118   # For master, we shouldn't ever be loading per-environment code into the master's
119   # ruby process, but that requires fixing (#17210, #12173, #8750). So for now
120   # we try to restrict to only code that can be autoloaded from the node's
121   # environment.
122 
123   # PUP-2114 - at this point in the bootstrapping process we do not
124   # have an appropriate application-wide current_environment set.
125   # If we cannot find the configured environment, which may not exist,
126   # we do not attempt to add plugin directories to the load path.
127   unless @subcommand_name == 'master' || @subcommand_name == 'agent' || (@subcommand_name == 'device' && (['--apply', '--facts', '--resource'] - @command_line.args).empty?)
128     configured_environment = Puppet.lookup(:environments).get(Puppet[:environment])
129     if configured_environment
130       configured_environment.each_plugin_directory do |dir|
131         $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
132       end
133 
134       Puppet::ModuleTranslations.load_from_modulepath(configured_environment.modules)
135       Puppet::ModuleTranslations.load_from_vardir(Puppet[:vardir])
136 
137       # Puppet requires Facter, which initializes its lookup paths. Reset Facter to
138       # pickup the new $LOAD_PATH.
139       Puppet.runtime[:facter].reset
140     end
141   end
142 
143   app = Puppet::Application.find(@subcommand_name).new(@command_line)
144   app.run
145 end