class Puppet::Util::CommandLine

This is the main entry point for all puppet applications / faces; it is basically where the bootstrapping process / lifecycle of an app begins.

Constants

OPTION_OR_MANIFEST_FILE

Public Class Methods

available_subcommands() click to toggle source

@api private @deprecated

# File lib/puppet/util/command_line.rb, line 60
def self.available_subcommands
  Puppet.deprecation_warning('Puppet::Util::CommandLine.available_subcommands is deprecated; please use Puppet::Application.available_application_names instead.')
  Puppet::Application.available_application_names
end
new(zero = $0, argv = ARGV, stdin = STDIN) click to toggle source

@param zero [String] the name of the executable @param argv [Array<String>] the arguments passed on the command line @param stdin [IO] (unused)

# File lib/puppet/util/command_line.rb, line 28
def initialize(zero = $0, argv = ARGV, stdin = STDIN)
  @command = File.basename(zero, '.rb')
  @argv = argv
  Puppet::Plugins.on_commandline_initialization(:command_line_object => self)
end

Public Instance Methods

args() click to toggle source

@return [Array<String>] the command line arguments being passed to the subcommand @api public

# File lib/puppet/util/command_line.rb, line 48
def args
  return @argv if @command != 'puppet'

  if subcommand_name.nil?
    @argv
  else
    @argv[1..-1]
  end
end
available_subcommands() click to toggle source

::available_subcommands was previously an instance method, not a class method, and we have an unknown number of user-implemented applications that depend on that behaviour. Forwarding allows us to preserve a backward compatible API. --daniel 2011-04-11 @api private @deprecated

# File lib/puppet/util/command_line.rb, line 71
def available_subcommands
  Puppet.deprecation_warning('Puppet::Util::CommandLine#available_subcommands is deprecated; please use Puppet::Application.available_application_names instead.')
  Puppet::Application.available_application_names
end
execute() click to toggle source

Run the puppet subcommand. If the subcommand is determined to be an external executable, this method will never return and the current process will be replaced via {Kernel#exec}.

@return [void]

# File lib/puppet/util/command_line.rb, line 81
def execute
  Puppet::Util.exit_on_fail("intialize global default settings") do
    Puppet.initialize_settings(args)
  end

  find_subcommand.run
end
external_subcommand() click to toggle source

@api private

# File lib/puppet/util/command_line.rb, line 90
def external_subcommand
  Puppet::Util.which("puppet-#{subcommand_name}")
end
subcommand_name() click to toggle source

@return [String] name of the subcommand is being executed @api public

# File lib/puppet/util/command_line.rb, line 36
def subcommand_name
  return @command if @command != 'puppet'

  if @argv.first =~ OPTION_OR_MANIFEST_FILE
    nil
  else
    @argv.first
  end
end