capssh 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/capssh +13 -2
  2. data/lib/capssh.rb +9 -4
  3. data/lib/capssh/version.rb +1 -1
  4. metadata +2 -2
data/bin/capssh CHANGED
@@ -18,7 +18,7 @@ require 'optparse'
18
18
  require 'capistrano'
19
19
 
20
20
  options = {:role => :app}
21
- OptionParser.new do |opts|
21
+ option_parser = OptionParser.new do |opts|
22
22
  opts.banner = "Usage: capssh [options]"
23
23
 
24
24
  opts.on("-e ENVIRONMENT", "--environment ENVIRONMENT", "Specify the environment to connect to") do |env|
@@ -33,6 +33,10 @@ OptionParser.new do |opts|
33
33
  options[:console] = true
34
34
  end
35
35
 
36
+ opts.on("-l", "--list", "List the servers defined for the specified environment/role.") do
37
+ options[:list_servers] = true
38
+ end
39
+
36
40
  opts.on_tail("-h", "--help", "Show this message") do
37
41
  puts opts
38
42
  exit
@@ -42,7 +46,14 @@ OptionParser.new do |opts|
42
46
  puts Capssh::VERSION
43
47
  exit
44
48
  end
45
- end.parse!
49
+ end
50
+
51
+ begin
52
+ option_parser.parse!
53
+ rescue OptionParser::InvalidOption => e
54
+ puts option_parser
55
+ exit
56
+ end
46
57
 
47
58
  options[:environment] ||= ARGV[0]
48
59
  Capssh.execute(options)
data/lib/capssh.rb CHANGED
@@ -3,8 +3,13 @@ module Capssh
3
3
 
4
4
  def execute(options={})
5
5
  config = load_capistrano_configuration(options)
6
- server = find_server(config, options)
7
- exec_ssh_command ssh_command(config, server, options)
6
+ servers = find_servers(config, options)
7
+
8
+ if options[:list_servers]
9
+ log servers.join(', ')
10
+ else
11
+ exec_ssh_command ssh_command(config, servers.first, options)
12
+ end
8
13
  end
9
14
 
10
15
  private
@@ -28,12 +33,12 @@ module Capssh
28
33
  config
29
34
  end
30
35
 
31
- def find_server(config, options)
36
+ def find_servers(config, options)
32
37
  servers = config.find_servers(:roles => options[:role])
33
38
  if servers.empty?
34
39
  display_error_and_exit("No servers could be found for environment '#{options[:environment]}' and role '#{options[:role]}'")
35
40
  end
36
- servers.first
41
+ servers
37
42
  end
38
43
 
39
44
  def ssh_command(config, server, options)
@@ -1,3 +1,3 @@
1
1
  module Capssh
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
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.6
4
+ version: 0.0.7
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-19 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec