module Capistrano::Console

Public Instance Methods

execute_ssh_locally(cmd='') click to toggle source
# File lib/capistrano_misc_recipes/console.rb, line 11
def execute_ssh_locally cmd=''
  hostname = find_servers_for_task(current_task).first
  local_ssh_command = ["ssh"]
  local_ssh_command << "-l #{user}" if fetch(:user, nil)
  local_ssh_command << hostname
  local_ssh_command << "-p #{port}" if fetch(:port, nil)
  local_ssh_command << "-t 'cd #{current_path}#{ cmd != '' ? ' && ' + cmd : '' }'"
  local_ssh_command = local_ssh_command.join " "

  logger.trace "executing locally: #{local_ssh_command.inspect}" if logger
  system local_ssh_command

  if $?.to_i > 0 # $? is command exit code (posix style)
    raise Capistrano::CommandError, "Command '#{cmd}' returned status code #{$?}"
  end
end