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

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
33 def initialize(zero = $0, argv = ARGV, stdin = STDIN)
34   @command = File.basename(zero, '.rb')
35   @argv = argv
36 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
52 def args
53   return @argv if @command != 'puppet'
54 
55   if subcommand_name.nil?
56     @argv
57   else
58     @argv[1..-1]
59   end
60 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
67 def execute
68   require_config = true
69   if @argv.first =~ /help|-h|--help|-V|--version/
70     require_config = false
71   end
72   Puppet::Util.exit_on_fail(_("Could not initialize global default settings")) do
73     Puppet.initialize_settings(args, require_config)
74   end
75 
76   setpriority(Puppet[:priority])
77 
78   find_subcommand.run
79 end
external_subcommand() click to toggle source

@api private

   # File lib/puppet/util/command_line.rb
82 def external_subcommand
83   Puppet::Util.which("puppet-#{subcommand_name}")
84 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
40 def subcommand_name
41   return @command if @command != 'puppet'
42 
43   if @argv.first =~ OPTION_OR_MANIFEST_FILE
44     nil
45   else
46     @argv.first
47   end
48 end

Private Instance Methods

find_subcommand() click to toggle source
    # File lib/puppet/util/command_line.rb
 88 def find_subcommand
 89   if subcommand_name.nil?
 90     if args.include?("--help") || args.include?("-h")
 91       ApplicationSubcommand.new("help", CommandLine.new("puppet", ["help"]))
 92     else
 93       NilSubcommand.new(self)
 94     end
 95   elsif Puppet::Application.available_application_names.include?(subcommand_name)
 96     ApplicationSubcommand.new(subcommand_name, self)
 97   else
 98     path_to_subcommand = external_subcommand
 99     if path_to_subcommand
100       ExternalSubcommand.new(path_to_subcommand, self)
101     else
102       UnknownSubcommand.new(subcommand_name, self)
103     end
104   end
105 end