Class: Puppet::Util::CommandLine
- Includes:
- Limits
- Defined in:
- lib/puppet/util/command_line.rb,
lib/puppet/util/command_line/trollop.rb,
lib/puppet/util/command_line/puppet_option_parser.rb
Overview
This is the main entry point for all puppet applications / faces; it is basically where the bootstrapping process / lifecycle of an app begins.
Defined Under Namespace
Modules: Trollop Classes: ApplicationSubcommand, ExternalSubcommand, NilSubcommand, PuppetOptionError, PuppetOptionParser, TrollopCommandlineError, UnknownSubcommand
Constant Summary collapse
- OPTION_OR_MANIFEST_FILE =
/^-|\.pp$/
Instance Method Summary collapse
-
#args ⇒ Array<String>
The command line arguments being passed to the subcommand.
-
#execute ⇒ void
Run the puppet subcommand.
- #external_subcommand ⇒ Object private
-
#initialize(zero = $PROGRAM_NAME, argv = ARGV, stdin = STDIN) ⇒ CommandLine
constructor
A new instance of CommandLine.
-
#subcommand_name ⇒ String
Name of the subcommand is being executed.
Methods included from Limits
Constructor Details
#initialize(zero = $PROGRAM_NAME, argv = ARGV, stdin = STDIN) ⇒ CommandLine
Returns a new instance of CommandLine.
34 35 36 37 |
# File 'lib/puppet/util/command_line.rb', line 34 def initialize(zero = $PROGRAM_NAME, argv = ARGV, stdin = STDIN) @command = File.basename(zero, '.rb') @argv = argv end |
Instance Method Details
#args ⇒ Array<String>
Returns the command line arguments being passed to the subcommand.
53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/util/command_line.rb', line 53 def args return @argv if @command != 'puppet' if subcommand_name.nil? @argv else @argv[1..] end end |
#execute ⇒ void
This method returns an undefined value.
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.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet/util/command_line.rb', line 68 def execute require_config = true if @argv.first =~ /help|-h|--help|-V|--version/ require_config = false end Puppet::Util.exit_on_fail(_("Could not initialize global default settings")) do Puppet.initialize_settings(args, require_config) end setpriority(Puppet[:priority]) find_subcommand.run end |
#external_subcommand ⇒ Object
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.
83 84 85 |
# File 'lib/puppet/util/command_line.rb', line 83 def external_subcommand Puppet::Util.which("puppet-#{subcommand_name}") end |
#subcommand_name ⇒ String
Returns name of the subcommand is being executed.
41 42 43 44 45 46 47 48 49 |
# File 'lib/puppet/util/command_line.rb', line 41 def subcommand_name return @command if @command != 'puppet' if @argv.first =~ OPTION_OR_MANIFEST_FILE nil else @argv.first end end |