capssh 0.0.1

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 +42 -0
  2. data/lib/capssh/version.rb +3 -0
  3. data/lib/capssh.rb +43 -0
  4. metadata +51 -0
data/bin/capssh ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'capssh'
5
+ require 'capssh/version'
6
+
7
+ if File.exist?('Gemfile')
8
+ require 'bundler'
9
+ begin
10
+ Bundler.setup(:default, :development)
11
+ rescue Bundler::BundlerError => e
12
+ $stderr.puts e.message
13
+ $stderr.puts "Run `bundle install` to install missing gems"
14
+ exit e.status_code
15
+ end
16
+ end
17
+
18
+ options = {:role => :app}
19
+ OptionParser.new do |opts|
20
+ opts.banner = "Usage: capssh [options]"
21
+
22
+ opts.on("-e ENVIRONMENT", "--environment ENVIRONMENT", "Specify the environment to connect to") do |env|
23
+ options[:environment] = env
24
+ end
25
+
26
+ opts.on("-r ROLE", "--role ROLE", "Specify the role of the machine to connect to. Defaults to :app.") do |role|
27
+ options[:role] = role
28
+ end
29
+
30
+ opts.on_tail("-h", "--help", "Show this message") do
31
+ puts opts
32
+ exit
33
+ end
34
+
35
+ opts.on_tail("-v", "--version", "Show version") do
36
+ puts Capssh::VERSION
37
+ exit
38
+ end
39
+ end.parse!
40
+
41
+ options[:environment] ||= ARGV[0]
42
+ Capssh.execute(options)
@@ -0,0 +1,3 @@
1
+ module Capssh
2
+ VERSION = "0.0.1"
3
+ end
data/lib/capssh.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'capistrano'
3
+
4
+ module Capssh
5
+ class << self
6
+
7
+ def execute(options={})
8
+ environment = options[:environment]
9
+ role = options[:role]
10
+
11
+ config = Capistrano::Configuration.new
12
+ config.load(:file => "./config/deploy.rb")
13
+
14
+ if environment
15
+ config_file = "./config/deploy/#{environment}.rb"
16
+ display_error_and_exit("No stage file exists for '#{environment}'") unless File.exist?(config_file)
17
+ config.load(:file => config_file)
18
+ end
19
+
20
+ if config.find_servers.empty?
21
+ display_error_and_exit("Please speicfy a valid environment: #{valid_environments.join(", ")}")
22
+ end
23
+
24
+ servers = config.find_servers(:roles => role)
25
+ display_error_and_exit("no servers could be found for environment '#{environment}' and role '#{role}'") if servers.empty?
26
+
27
+ user = config[:user] || ENV['USER']
28
+ server = servers.first
29
+ puts "Connecting to #{environment} #{role} at #{user}@#{server}..."
30
+ exec "ssh #{user}@#{server}"
31
+ end
32
+
33
+ def display_error_and_exit(error)
34
+ puts "ERROR: #{error}"
35
+ exit(1)
36
+ end
37
+
38
+ def valid_environments
39
+ Dir.entries("./config/deploy").select { |f| f =~ /.rb$/ }.map { |f| f.sub(".rb", "") }
40
+ end
41
+
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Wood
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A utility that allows you to easily SSH into a server defined in a capistrano
15
+ configuration file.
16
+ email:
17
+ - john@johnpwood.net
18
+ executables:
19
+ - capssh
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/capssh.rb
24
+ - lib/capssh/version.rb
25
+ - bin/capssh
26
+ homepage: https://github.com/centro/capssh
27
+ licenses:
28
+ - MIT
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.23
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Easily connect via SSH to different environments configured for this project.
51
+ test_files: []