capssh 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/capssh.rb +20 -7
  2. data/lib/capssh/version.rb +1 -1
  3. metadata +19 -3
data/lib/capssh.rb CHANGED
@@ -4,12 +4,14 @@ module Capssh
4
4
  def execute(options={})
5
5
  config = load_capistrano_configuration(options)
6
6
  server = find_server(config, options)
7
- exec ssh_command(config, server, options)
7
+ exec_ssh_command ssh_command(config, server, options)
8
8
  end
9
9
 
10
10
  private
11
11
 
12
12
  def load_capistrano_configuration(options)
13
+ display_error_and_exit("No capistrano config file could be found in ./config/deploy.rb") unless File.exist?("./config/deploy.rb")
14
+
13
15
  config = Capistrano::Configuration.new
14
16
  config.load(:file => "./config/deploy.rb")
15
17
 
@@ -29,36 +31,47 @@ module Capssh
29
31
  def find_server(config, options)
30
32
  servers = config.find_servers(:roles => options[:role])
31
33
  if servers.empty?
32
- display_error_and_exit("no servers could be found for environment '#{options[:environment]}' and role '#{options[:role]}'")
34
+ display_error_and_exit("No servers could be found for environment '#{options[:environment]}' and role '#{options[:role]}'")
33
35
  end
34
-
35
36
  servers.first
36
37
  end
37
38
 
38
39
  def ssh_command(config, server, options)
39
40
  user = config[:user] || ENV['USER']
40
41
 
41
- puts "Connecting to #{options[:environment]} #{options[:role]} at #{user}@#{server}..."
42
+ log "Connecting to #{options[:environment]} #{options[:role]} at #{user}@#{server}..."
42
43
  ssh_command = "ssh #{user}@#{server}"
43
44
 
44
45
  command = nil
45
46
  if options[:console]
46
- command = "cd #{config[:deploy_to]}/current; bundle exec rails console #{config[:rails_env]}"
47
+ command = "cd #{config[:deploy_to]}/current; if [ -f script/console ]; then bundle exec script/console #{config[:rails_env]}; else bundle exec rails console #{config[:rails_env]}; fi"
47
48
  end
48
49
 
49
50
  if command
50
- puts "Running command: #{command}"
51
+ log "Running command: #{command}"
51
52
  ssh_command += " -t \"#{command}\""
52
53
  end
53
54
 
54
55
  ssh_command
55
56
  end
56
57
 
58
+ def exec_ssh_command(cmd)
59
+ exec cmd
60
+ end
61
+
57
62
  def display_error_and_exit(error)
58
- puts "ERROR: #{error}"
63
+ display_error(error)
59
64
  exit(1)
60
65
  end
61
66
 
67
+ def display_error(error)
68
+ log "ERROR: #{error}"
69
+ end
70
+
71
+ def log(message)
72
+ puts message
73
+ end
74
+
62
75
  def valid_environments
63
76
  Dir.entries("./config/deploy").select { |f| f =~ /.rb$/ }.map { |f| f.sub(".rb", "") }
64
77
  end
@@ -1,3 +1,3 @@
1
1
  module Capssh
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: A utility that allows you to easily SSH into a server defined in a capistrano
15
31
  configuration file.
16
32
  email: