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$|\.rb$/
Class Method Summary collapse
- .available_subcommands ⇒ Object deprecated private Deprecated.
Instance Method Summary collapse
-
#args ⇒ Array<String>
The command line arguments being passed to the subcommand.
- #available_subcommands ⇒ Object deprecated private Deprecated.
-
#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.
32 33 34 35 36 |
# File 'lib/puppet/util/command_line.rb', line 32 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 |
Class Method Details
.available_subcommands ⇒ 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.
64 65 66 67 |
# File 'lib/puppet/util/command_line.rb', line 64 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 |
Instance Method Details
#args ⇒ Array<String>
Returns the command line arguments being passed to the subcommand.
52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/util/command_line.rb', line 52 def args return @argv if @command != 'puppet' if subcommand_name.nil? @argv else @argv[1..-1] end end |
#available_subcommands ⇒ 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.
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
75 76 77 78 |
# File 'lib/puppet/util/command_line.rb', line 75 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 ⇒ 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.
85 86 87 88 89 90 91 92 93 |
# File 'lib/puppet/util/command_line.rb', line 85 def execute Puppet::Util.exit_on_fail("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.
96 97 98 |
# File 'lib/puppet/util/command_line.rb', line 96 def external_subcommand Puppet::Util.which("puppet-#{subcommand_name}") end |
#subcommand_name ⇒ String
Returns name of the subcommand is being executed.
40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/util/command_line.rb', line 40 def subcommand_name return @command if @command != 'puppet' if @argv.first =~ OPTION_OR_MANIFEST_FILE nil else @argv.first end end |