class RHC::Commands::Ssh

Public Instance Methods

run(app_name, command) click to toggle source
# File lib/rhc/commands/ssh.rb, line 28
def run(app_name, command)
  raise ArgumentError, "No application specified" unless app_name.present?
  raise ArgumentError, "--gears requires a command" if options.gears && command.blank?
  raise ArgumentError, "--limit must be an integer greater than zero" if options.limit && options.limit < 1
  raise OptionParser::InvalidOption, "No system SSH available. Please use the --ssh option to specify the path to your SSH executable, or install SSH." unless options.ssh or has_ssh?

  if options.gears
    groups = rest_client.find_application_gear_groups(options.namespace, app_name)
    run_on_gears(command.join(' '), groups)
    0
  else
    rest_app = rest_client.find_application(options.namespace, app_name)
    $stderr.puts "Connecting to #{rest_app.ssh_string.to_s} ..." unless command.present?

    ssh = options.ssh || 'ssh'
    debug "Using user specified SSH: #{options.ssh}" if options.ssh

    command_line = [ssh, rest_app.ssh_string.to_s, command].compact.flatten
    debug "Invoking Kernel.exec with #{command_line.inspect}"
    Kernel.send(:exec, *command_line)
  end
end