Class: Puppet::Util::CommandLine

Inherits:
Object
  • Object
show all
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

Methods included from Limits

#setpriority

Constructor Details

#initialize(zero = $PROGRAM_NAME, argv = ARGV, stdin = STDIN) ⇒ CommandLine

Returns a new instance of CommandLine.

Parameters:

  • zero (String) (defaults to: $PROGRAM_NAME)

    the name of the executable

  • argv (Array<String>) (defaults to: ARGV)

    the arguments passed on the command line

  • stdin (IO) (defaults to: STDIN)

    (unused)

 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

#argsArray<String>

Returns the command line arguments being passed to the subcommand.

Returns:

  • (Array<String>)

    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

#executevoid

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_subcommandObject

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_nameString

Returns name of the subcommand is being executed.

Returns:

  • (String)

    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