From 3debb2fc57d79a1d9ea3931949f442236d1e3aa7 Mon Sep 17 00:00:00 2001 From: Florian Schwab Date: Thu, 12 Nov 2015 23:27:52 +0100 Subject: [PATCH] use capistrano-interactive for connection stuff --- CHANGELOG.md | 6 ++- capistrano-rails-console.gemspec | 3 +- lib/capistrano/rails/console/remote.rb | 2 + lib/capistrano/rails/console/tasks/remote.cap | 50 ++++--------------- lib/capistrano/rails/console/version.rb | 4 +- 5 files changed, 20 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 691436b..4f98fc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log -## 1.0.0 (2015-11-12) +## Unreleased +### Changed +- switched connection part to _capistrano-interactive_ + +## 1.0.1 (2015-11-12) ### Fixed - setting ssh hostname through `ssh_options` - use login shell diff --git a/capistrano-rails-console.gemspec b/capistrano-rails-console.gemspec index eac2218..b380f5a 100644 --- a/capistrano-rails-console.gemspec +++ b/capistrano-rails-console.gemspec @@ -18,7 +18,8 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0' + spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0' + spec.add_dependency 'capistrano-interactive', '~> 0.2.0' spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake' diff --git a/lib/capistrano/rails/console/remote.rb b/lib/capistrano/rails/console/remote.rb index 594d2ac..8a333dd 100644 --- a/lib/capistrano/rails/console/remote.rb +++ b/lib/capistrano/rails/console/remote.rb @@ -1 +1,3 @@ +require 'capistrano/interactive' + load File.expand_path('../tasks/remote.cap', __FILE__) diff --git a/lib/capistrano/rails/console/tasks/remote.cap b/lib/capistrano/rails/console/tasks/remote.cap index e6af035..51a8512 100644 --- a/lib/capistrano/rails/console/tasks/remote.cap +++ b/lib/capistrano/rails/console/tasks/remote.cap @@ -1,55 +1,23 @@ namespace :load do task :defaults do - # add rails to rvm_map_bins + # Add rails to rvm_map_bins set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails) + + # Default values + set :console_env, -> { fetch(:rails_env, fetch(:stage, 'production')) } 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 + args = [] + args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s') - 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}\"" + on primary(:app) do + within current_path do + interact(:rails, :console, fetch(:console_env), *args) end - - if host.ssh_options && host.ssh_options[:host_name] - ssh_cmd_args << "-o HostName=\"#{host.ssh_options[:host_name]}\"" - end - - rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s') - - 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 - - port = host.port || (host.ssh_options || {})[:port] - ssh_cmd_args << "-p #{port}" if port - - ssh_user = if host.ssh_options && host.ssh_options[:user] - host.ssh_options[:user] - else - host.user - end - ssh_cmd_args << [ssh_user, host.hostname].compact.join('@') - - if host.ssh_options && host.ssh_options[:keys] && host.ssh_options[:keys].length > 0 - identity = host.ssh_options[:keys][0] - ssh_cmd_args << "-i #{identity}" - end - - ssh_cmd = %Q(ssh #{ssh_cmd_args.join(' ')} -t '$SHELL -l -c "cd #{current_path} && (#{cmd.environment_string} #{cmd})"') - - debug("Running #{ssh_cmd.yellow} on #{host.hostname.blue}") - - exec(ssh_cmd) end end end diff --git a/lib/capistrano/rails/console/version.rb b/lib/capistrano/rails/console/version.rb index 028defe..31d09dc 100644 --- a/lib/capistrano/rails/console/version.rb +++ b/lib/capistrano/rails/console/version.rb @@ -4,8 +4,8 @@ module Capistrano module Rails # Console module Console - # gem version - VERSION = '1.0.1' + # Gem version + VERSION = '1.1.0' end end end