capssh 0.0.4 → 0.0.5

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/version.rb +1 -1
  2. data/lib/capssh.rb +26 -11
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Capssh
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/capssh.rb CHANGED
@@ -2,15 +2,20 @@ module Capssh
2
2
  class << self
3
3
 
4
4
  def execute(options={})
5
- environment = options[:environment]
6
- role = options[:role]
5
+ config = load_capistrano_configuration(options)
6
+ server = find_server(config, options)
7
+ exec ssh_command(config, server, options)
8
+ end
9
+
10
+ private
7
11
 
12
+ def load_capistrano_configuration(options)
8
13
  config = Capistrano::Configuration.new
9
14
  config.load(:file => "./config/deploy.rb")
10
15
 
11
- if environment
12
- config_file = "./config/deploy/#{environment}.rb"
13
- display_error_and_exit("No stage file exists for '#{environment}'") unless File.exist?(config_file)
16
+ if options[:environment]
17
+ config_file = "./config/deploy/#{options[:environment]}.rb"
18
+ display_error_and_exit("No stage file exists for '#{options[:environment]}'") unless File.exist?(config_file)
14
19
  config.load(:file => config_file)
15
20
  end
16
21
 
@@ -18,25 +23,35 @@ module Capssh
18
23
  display_error_and_exit("Please specify a valid environment: #{valid_environments.join(", ")}")
19
24
  end
20
25
 
21
- servers = config.find_servers(:roles => role)
22
- display_error_and_exit("no servers could be found for environment '#{environment}' and role '#{role}'") if servers.empty?
26
+ config
27
+ end
28
+
29
+ def find_server(config, options)
30
+ servers = config.find_servers(:roles => options[:role])
31
+ if servers.empty?
32
+ display_error_and_exit("no servers could be found for environment '#{options[:environment]}' and role '#{options[:role]}'")
33
+ end
34
+
35
+ servers.first
36
+ end
23
37
 
38
+ def ssh_command(config, server, options)
24
39
  user = config[:user] || ENV['USER']
25
- server = servers.first
26
- puts "Connecting to #{environment} #{role} at #{user}@#{server}..."
40
+
41
+ puts "Connecting to #{options[:environment]} #{options[:role]} at #{user}@#{server}..."
42
+ ssh_command = "ssh #{user}@#{server}"
27
43
 
28
44
  command = nil
29
45
  if options[:console]
30
46
  command = "cd #{config[:deploy_to]}/current; bundle exec rails console #{config[:rails_env]}"
31
47
  end
32
48
 
33
- ssh_command = "ssh #{user}@#{server}"
34
49
  if command
35
50
  puts "Running command: #{command}"
36
51
  ssh_command += " -t \"#{command}\""
37
52
  end
38
53
 
39
- exec ssh_command
54
+ ssh_command
40
55
  end
41
56
 
42
57
  def display_error_and_exit(error)
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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A utility that allows you to easily SSH into a server defined in a capistrano
15
15
  configuration file.