Class: Puppet::Util::CommandLine
- Defined in:
- lib/puppet/util/command_line.rb
Constant Summary collapse
- LegacyName =
Hash.new{|h,k| k}.update( 'agent' => 'puppetd', 'cert' => 'puppetca', 'doc' => 'puppetdoc', 'filebucket' => 'filebucket', 'apply' => 'puppet', 'describe' => 'pi', 'queue' => 'puppetqd', 'resource' => 'ralsh', 'kick' => 'puppetrun', 'master' => 'puppetmasterd' )
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#subcommand_name ⇒ Object
readonly
Returns the value of attribute subcommand_name.
Instance Method Summary collapse
- #appdir ⇒ Object
- #available_subcommands ⇒ Object
- #execute ⇒ Object
- #execute_external_subcommand ⇒ Object
-
#initialize(zero = $0, argv = ARGV, stdin = STDIN) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #legacy_executable_name ⇒ Object
- #require_application(application) ⇒ Object
- #usage_message ⇒ Object
Constructor Details
#initialize(zero = $0, argv = ARGV, stdin = STDIN) ⇒ CommandLine
Returns a new instance of CommandLine.
20 21 22 23 24 25 26 27 |
# File 'lib/puppet/util/command_line.rb', line 20 def initialize( zero = $0, argv = ARGV, stdin = STDIN ) @zero = zero @argv = argv.dup @stdin = stdin @subcommand_name, @args = subcommand_and_args( @zero, @argv, @stdin ) Puppet::Plugins.on_commandline_initialization(:command_line_object => self) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
30 31 32 |
# File 'lib/puppet/util/command_line.rb', line 30 def args @args end |
#subcommand_name ⇒ Object (readonly)
Returns the value of attribute subcommand_name.
29 30 31 |
# File 'lib/puppet/util/command_line.rb', line 29 def subcommand_name @subcommand_name end |
Instance Method Details
#appdir ⇒ Object
32 33 34 |
# File 'lib/puppet/util/command_line.rb', line 32 def appdir File.join('puppet', 'application') end |
#available_subcommands ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/puppet/util/command_line.rb', line 36 def available_subcommands absolute_appdirs = $LOAD_PATH.collect do |x| File.join(x,'puppet','application') end.select{ |x| File.directory?(x) } absolute_appdirs.inject([]) do |commands, dir| commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')} end.uniq end |
#execute ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet/util/command_line.rb', line 55 def execute if subcommand_name.nil? puts elsif available_subcommands.include?(subcommand_name) #subcommand require_application subcommand_name app = Puppet::Application.find(subcommand_name).new(self) Puppet::Plugins.on_application_initialization(:appliation_object => self) app.run else abort "Error: Unknown command #{subcommand_name}.\n#{}" unless execute_external_subcommand end end |
#execute_external_subcommand ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/util/command_line.rb', line 68 def execute_external_subcommand external_command = "puppet-#{subcommand_name}" require 'puppet/util' path_to_subcommand = Puppet::Util.which( external_command ) return false unless path_to_subcommand system( path_to_subcommand, *args ) true end |
#legacy_executable_name ⇒ Object
79 80 81 |
# File 'lib/puppet/util/command_line.rb', line 79 def legacy_executable_name LegacyName[ subcommand_name ] end |
#require_application(application) ⇒ Object
51 52 53 |
# File 'lib/puppet/util/command_line.rb', line 51 def require_application(application) require File.join(appdir, application) end |
#usage_message ⇒ Object
45 46 47 48 49 |
# File 'lib/puppet/util/command_line.rb', line 45 def usage = "Usage: puppet command <space separated arguments>" available = "Available commands are: #{available_subcommands.sort.join(', ')}" [usage, available].join("\n") end |