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 32 def initialize(zero = $0, argv = ARGV, stdin = STDIN) 33 @command = File.basename(zero, '.rb') 34 @argv = argv 35 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 51 def args 52 return @argv if @command != 'puppet' 53 54 if subcommand_name.nil? 55 @argv 56 else 57 @argv[1..-1] 58 end 59 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 66 def execute 67 require_config = true 68 if @argv.first =~ /help|-h|--help|-V|--version/ 69 require_config = false 70 end 71 Puppet::Util.exit_on_fail(_("Could not initialize global default settings")) do 72 Puppet.initialize_settings(args, require_config) 73 end 74 75 setpriority(Puppet[:priority]) 76 77 find_subcommand.run 78 end
external_subcommand()
click to toggle source
@api private
# File lib/puppet/util/command_line.rb 81 def external_subcommand 82 Puppet::Util.which("puppet-#{subcommand_name}") 83 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 39 def subcommand_name 40 return @command if @command != 'puppet' 41 42 if @argv.first =~ OPTION_OR_MANIFEST_FILE 43 nil 44 else 45 @argv.first 46 end 47 end
Private Instance Methods
find_subcommand()
click to toggle source
# File lib/puppet/util/command_line.rb 87 def find_subcommand 88 if subcommand_name.nil? 89 if args.include?("--help") || args.include?("-h") 90 ApplicationSubcommand.new("help", CommandLine.new("puppet", ["help"])) 91 else 92 NilSubcommand.new(self) 93 end 94 elsif Puppet::Application.available_application_names.include?(subcommand_name) 95 ApplicationSubcommand.new(subcommand_name, self) 96 else 97 path_to_subcommand = external_subcommand 98 if path_to_subcommand 99 ExternalSubcommand.new(path_to_subcommand, self) 100 else 101 UnknownSubcommand.new(subcommand_name, self) 102 end 103 end 104 end