capx 0.0.1 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90d9fadb5c34ec37b26166c249fd9200003df8ffc6d37ad609221ee41b35ae4e
4
- data.tar.gz: 0616ad5d41083b59ae9986d0953fa440fa4461476953583f62ab46e25d9d1a69
3
+ metadata.gz: dd216d3a6b185ec5cef9e617c575827b88d0a567eb84d6656e975bb8749dc1b8
4
+ data.tar.gz: f1918582c9098658d87b867b5d65eee15ac61ceda37dc7259371ab8364d7140c
5
5
  SHA512:
6
- metadata.gz: 4db1cc6b230c9a4a8cc7544380982b8ac253f91a73c7b01fb75cc0293794d33618b0cae08c17c8d6dfa64723e5dd977b2f95d6f39adea0b657573a3005feacd1
7
- data.tar.gz: 4d99d65c10157faf1b275669e29d7d4a39c86e020ff933eddcd43aef39bd833b2254f6ef26e49fd54ea2a0d3a73d505a34c19afdb0ef3d179be49980feb2d45d
6
+ metadata.gz: 18bb4ac06dc1a4815dab625a4185f936663614b9ab3adfa1d7cdbbb8dbdc26fa54b113658bb45f82bc6b01f02cca4a806a058e678d0df93efde756ccda600edc
7
+ data.tar.gz: cde385113112938caa2ad63fe45bb609f92f01148c8ff41fe47fb3114f10136dee535d449f6cc5a9bef90c444ae839051ccf210ed9314c3026f870aa8861756a
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # CapX
2
+
3
+ Generates SSH commands using capistrano deploy configuration. \
4
+ SSH username and host are parsed from capistrano deploy configuration. \
5
+ \
6
+ capistrano deploy configuration:
7
+
8
+ server 'dev.example.com', user: 'deploy', roles: %w{web app db}, primary: true
9
+ generated SSH command:
10
+
11
+ $ ssh deploy@dev.example.com
12
+
13
+ ## Installation
14
+
15
+
16
+ $ gem install capx
17
+
18
+
19
+ ## Usage
20
+
21
+
22
+
23
+ This will add the following executable in your shell:
24
+
25
+
26
+ capx [stage] [ssh|disk|info|redis] [user]
27
+
28
+
29
+ ### Examples:
30
+
31
+ $ capx staging # show ssh command
32
+ $ capx production ssh # execute ssh command
33
+ $ capx production ssh root # execute ssh command with root user
34
+ $ capx production disk # execute ssh 'df -H' command
35
+ $ capx production redis # execute ssh 'redis-cli INFO keyspace' command
data/bin/capx CHANGED
@@ -6,15 +6,16 @@ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
6
6
  require 'capx'
7
7
 
8
8
  def show_help
9
- puts 'params: <stage> <switch>'
9
+ puts 'params: <stage> <ssh|disk|info|redis> <user>'
10
10
  puts 'example: capx staging ssh'
11
11
  end
12
12
 
13
13
  if ARGV[0]
14
14
  stage = ARGV[0]
15
- param = ARGV[1]
15
+ switch = ARGV[1]
16
+ user = ARGV[2]
16
17
 
17
- runner = Capx::Runner.new(stage: stage, param: param)
18
+ runner = Capx::Runner.new(stage: stage, switch: switch, user: user)
18
19
  runner.run
19
20
  else
20
21
  show_help
data/capx.gemspec CHANGED
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.required_ruby_version = '>= 2.2.0'
11
11
  spec.authors = ['Jan Kmet']
12
12
  spec.email = ['jan.kmet@gmail.com']
13
- spec.summary = 'SSH shortcut using capistrano deploy configuration'
13
+ spec.summary = 'Generates SSH command using capistrano deploy configuration.'
14
14
  spec.description = <<-EOF
15
- SSH shortcut using capistrano deploy configuration.
15
+ Generates SSH command using capistrano deploy configuration..
16
16
  SSH username and host are parsed from capistrano deploy configuration
17
17
  EOF
18
18
  spec.homepage = 'https://github.com/jankmet/capx'
data/lib/capx/runner.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  module Capx
2
2
  class Runner
3
- PATTERN = /server:?\s+[\'\"]([\w\-\.]+)[\'\"],\s+user:?\s+[\'\"]([\w\-\.]+)[\'\"]/
3
+ PATTERN = /server:?\s+[\'\"]([\w\-\.]+)[\'\"],\s+user:?\s+[\'\"]([\w\-\.]+)[\'\"]/
4
+ DIR_PATTERN = /set :deploy_to,\s+[\'\"](?<path>(.+)\/([^\/]+))[\'\"]/
4
5
 
5
6
  def initialize(options)
6
7
  @stage = options[:stage]
7
8
  @switch = options[:switch]
9
+ @user = options[:user]
8
10
  @server = nil
9
- @user = nil
10
11
  end
11
12
 
12
13
  def run
@@ -15,25 +16,51 @@ module Capx
15
16
  File.open(file).each do |line|
16
17
  if match = PATTERN.match(line)
17
18
  @server = match.captures[0]
18
- @user = match.captures[1]
19
- end
19
+ @user = match.captures[1] if @user.nil?
20
+ end
21
+
22
+ if match = DIR_PATTERN.match(line)
23
+ @deploy_to = File.join(match[:path], 'current')
24
+ end
20
25
  end
21
26
 
22
27
  if @server.nil? || @user.nil?
23
- puts "capistrano server/user not found"
28
+ puts 'capistrano server/user not found'
24
29
  else
25
- if ARGV[1] == 'ssh'
26
- # call ssh
27
- cmd = "ssh #{@user}@#{@server}"
28
- puts "executing #{cmd}"
29
- exec(cmd)
30
- else
30
+ ssh_cmd = "ssh #{@user}@#{@server}"
31
+
32
+ if @switch == 'ssh'
33
+ # call ssh
34
+ ssh_cmd = "ssh -t #{@user}@#{@server} \"cd #{@deploy_to}; exec /bin/bash -l\"" unless @deploy_to.nil?
35
+
36
+ cmd = ssh_cmd
37
+ execute_cmd(cmd)
38
+ elsif @switch == 'disk'
39
+ # call remote df -H
40
+ cmd = "#{ssh_cmd} 'df -H'"
41
+ execute_cmd(cmd)
42
+ elsif @switch == 'info'
43
+ # call remote cat /etc/*-release
44
+ cmd = "#{ssh_cmd} 'cat /etc/*-release'"
45
+ execute_cmd(cmd)
46
+ elsif @switch == 'redis'
47
+ # call remote redis-cli INFO keyspace
48
+ cmd = "#{ssh_cmd} 'redis-cli INFO keyspace'"
49
+ execute_cmd(cmd)
50
+ else
31
51
  puts "#{@user}@#{@server}"
32
- end
52
+ end
33
53
  end
34
54
  else
35
55
  puts "File #{file} not found"
36
- end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def execute_cmd(cmd)
62
+ puts "executing #{cmd}"
63
+ exec(cmd)
37
64
  end
38
65
  end
39
- end
66
+ end
data/lib/capx/version.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # main module for capx
2
2
  module Capx
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.6'
4
4
  end
5
-
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Kmet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-06 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
- SSH shortcut using capistrano deploy configuration.
14
+ Generates SSH command using capistrano deploy configuration..
15
15
  SSH username and host are parsed from capistrano deploy configuration
16
16
  email:
17
17
  - jan.kmet@gmail.com
@@ -22,6 +22,7 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - ".gitignore"
24
24
  - LICENSE
25
+ - README.md
25
26
  - bin/capx
26
27
  - capx.gemspec
27
28
  - lib/capx.rb
@@ -31,7 +32,7 @@ homepage: https://github.com/jankmet/capx
31
32
  licenses:
32
33
  - MIT
33
34
  metadata: {}
34
- post_install_message:
35
+ post_install_message:
35
36
  rdoc_options: []
36
37
  require_paths:
37
38
  - lib
@@ -46,9 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  requirements: []
49
- rubyforge_project:
50
- rubygems_version: 2.7.6
51
- signing_key:
50
+ rubygems_version: 3.2.3
51
+ signing_key:
52
52
  specification_version: 4
53
- summary: SSH shortcut using capistrano deploy configuration
53
+ summary: Generates SSH command using capistrano deploy configuration.
54
54
  test_files: []