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 = $0, argv = ARGV, stdin = STDIN) ⇒ 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

#argsArray<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

#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.



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_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.



76
77
78
# File 'lib/puppet/util/command_line.rb', line 76

def external_subcommand
  Puppet::Util.which("puppet-#{subcommand_name}")
end

#subcommand_nameString

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