diff --git a/lib/capistrano/rails/console/tasks/remote.cap b/lib/capistrano/rails/console/tasks/remote.cap index f89876d..9d976a0 100644 --- a/lib/capistrano/rails/console/tasks/remote.cap +++ b/lib/capistrano/rails/console/tasks/remote.cap @@ -1,42 +1,42 @@ namespace :load do - task :defaults do - # add rails to rvm_map_bins - set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails) - end + task :defaults do + # add rails to rvm_map_bins + set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails) + end end namespace :rails do - desc "Interact with a remote rails console" - task :console do - on primary :app do |host| - test(:true) # initialize ssh_options on host + desc "Interact with a remote rails console" + task :console do + on primary :app do |host| + test(:true) # initialize ssh_options on host - ssh_cmd_args = [] - rails_console_args = [] + ssh_cmd_args = [] + rails_console_args = [] - if host.ssh_options && host.ssh_options[:proxy] - template = host.ssh_options[:proxy].command_line_template - ssh_cmd_args << "-o ProxyCommand=\"#{template}\"" - end + if host.ssh_options && host.ssh_options[:proxy] + template = host.ssh_options[:proxy].command_line_template + ssh_cmd_args << "-o ProxyCommand=\"#{template}\"" + end - rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s') + rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s') - rails_env = fetch(:rails_env, fetch(:stage, 'production')) + rails_env = fetch(:rails_env, fetch(:stage, 'production')) - cmd = SSHKit::Command.new(:rails, :console, rails_env, *rails_console_args, host: host) - SSHKit.config.output << cmd + cmd = SSHKit::Command.new(:rails, :console, rails_env, *rails_console_args, host: host) + SSHKit.config.output << cmd - port = host.port || (host.ssh_options || {})[:port] - ssh_cmd_args << "-p #{port}" if port + port = host.port || (host.ssh_options || {})[:port] + ssh_cmd_args << "-p #{port}" if port - ssh_cmd_args << [host.user, host.hostname].compact.join('@') + ssh_cmd_args << [host.user, host.hostname].compact.join('@') - if hosts.ssh_options && hosts.ssh_options[:keys] - identity = hosts.ssh_options[:keys][0] - ssh_cmd_args << "-i #{identity}" - end + if host.ssh_options && host.ssh_options[:keys] + identity = host.ssh_options[:keys][0] + ssh_cmd_args << "-i #{identity}" + end - exec(%Q(ssh #{ssh_cmd_args.join(' ')} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})")) - end - end + exec(%Q(ssh #{ssh_cmd_args.join(' ')} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})")) + end + end end