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 = $0, 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 = $0, argv = ARGV, stdin = STDIN) ⇒ CommandLine
Returns a new instance of CommandLine.
31 32 33 34 |
# File 'lib/puppet/util/command_line.rb', line 31 def initialize(zero = $0, 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.
50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/util/command_line.rb', line 50 def args return @argv if @command != 'puppet' if subcommand_name.nil? @argv else @argv[1..-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.
65 66 67 68 69 70 71 72 73 |
# File 'lib/puppet/util/command_line.rb', line 65 def execute Puppet::Util.exit_on_fail(_("Could not initialize global default settings")) do Puppet.initialize_settings(args) 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.
76 77 78 |
# File 'lib/puppet/util/command_line.rb', line 76 def external_subcommand Puppet::Util.which("puppet-#{subcommand_name}") end |
#subcommand_name ⇒ String
Returns name of the subcommand is being executed.
38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/util/command_line.rb', line 38 def subcommand_name return @command if @command != 'puppet' if @argv.first =~ OPTION_OR_MANIFEST_FILE nil else @argv.first end end |