capistrano-interactive 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 496fc2ae0c8f29d78ab4ef5e056e5539617b646d
4
+ data.tar.gz: 5c5f3dd4ed5a217a0f6e4cb0df1666bbb2e964d4
5
+ SHA512:
6
+ metadata.gz: 4daccbfa98652df1af42f647d873911a4c3c24ad5182396f7b2250e763e876ccea509951e15eff551db969b6f94b6c51c852f051a3b3ec4f99779a2738bf2581
7
+ data.tar.gz: 93d95b39436003db892ec564426433ef3fe70fd6d905575e2bcada2f6dd4847905639b9e90cebb371edbf280f00ec18eb3e9a27ff8b9ae8de73deb4cfcf072a4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-interactive-cmd.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Florian Schwab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ [![Gem Version](https://img.shields.io/gem/v/capistrano-interactive.svg)](https://rubygems.org/gems/capistrano-interactive)
2
+ [![Dependencies](https://img.shields.io/gemnasium/ydkn/capistrano-interactive.svg)](https://gemnasium.com/ydkn/capistrano-interactive)
3
+ [![Code Climate](https://img.shields.io/codeclimate/github/ydkn/capistrano-interactive.svg)](https://codeclimate.com/github/ydkn/capistrano-interactive)
4
+
5
+ [![Join the chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ydkn/capistrano-interactive)
6
+
7
+
8
+ # Capistrano::Interactive
9
+
10
+ Interactive command execution for capistrano.
11
+
12
+ TODO: Delete this and the text above, and describe your gem
13
+
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'capistrano-interactive'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install capistrano-interactive
30
+
31
+
32
+ ## Usage
33
+
34
+ Require in `Capfile` to use the default task:
35
+
36
+ ```ruby
37
+ require 'capistrano/interactive'
38
+ ```
39
+
40
+ Now you can start interactive programs through capistrano.
41
+
42
+ ```ruby
43
+ on primary(:app) do
44
+ interact(:htop)
45
+ end
46
+ ```
47
+
48
+ ```ruby
49
+ on primary(:app) do
50
+ within current_path do
51
+ interact(:rails, :console, rails_env)
52
+ end
53
+ end
54
+ ```
55
+
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydkn/capistrano-interactive.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'capistrano/interactive'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/interactive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-interactive'
8
+ spec.version = Capistrano::Interactive::VERSION
9
+ spec.authors = ['Florian Schwab']
10
+ spec.email = ['me@ydkn.de']
11
+
12
+ spec.summary = %q{Interactive command execution for capistrano}
13
+ spec.description = %q{Interactive command execution for capistrano}
14
+ spec.homepage = 'https://github.com/ydkn/capistrano-interactive'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0'
23
+ spec.add_dependency 'sshkit', '~> 1.7.0'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ end
@@ -0,0 +1,36 @@
1
+ module Capistrano
2
+ module Interactive
3
+ module BackendHook
4
+ def self.included(base)
5
+ base.class_eval do
6
+ alias_method :non_interactive_execute, :execute
7
+ def execute(*args)
8
+ if BackendHook.intercept_command?
9
+ BackendHook.last_command = command(*args)
10
+ else
11
+ non_interactive_execute(*args)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.intercept_command!
18
+ @intercept_command = true
19
+ end
20
+
21
+ def self.intercept_command?
22
+ !!@intercept_command
23
+ end
24
+
25
+ def self.last_command
26
+ @last_command
27
+ end
28
+
29
+ private
30
+
31
+ def self.last_command=(cmd)
32
+ @last_command = cmd
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,70 @@
1
+ module Capistrano
2
+ module Interactive
3
+ class Command
4
+ def initialize(host, command)
5
+ @host = host
6
+ @command = command
7
+ end
8
+
9
+ def to_cmd
10
+ [
11
+ :ssh,
12
+ *ssh_cmd_args,
13
+ @host.hostname,
14
+ %Q{'$SHELL -l -c "#{@command.to_command}"'}
15
+ ].join(' ')
16
+ end
17
+
18
+ def execute
19
+ exec(to_cmd)
20
+ end
21
+
22
+ private
23
+
24
+ def ssh_option(attr_name)
25
+ (@host.netssh_options || {})[attr_name] || (@host.respond_to?(attr_name) ? @host.send(attr_name) : nil)
26
+ end
27
+
28
+ def host_name
29
+ ssh_option(:host_name)
30
+ end
31
+
32
+ def port
33
+ ssh_option(:port)
34
+ end
35
+
36
+ def user
37
+ ssh_option(:user)
38
+ end
39
+
40
+ def forward_agent?
41
+ !!ssh_option(:forward_agent)
42
+ end
43
+
44
+ def proxy_command
45
+ ssh_option(:proxy) ? ssh_option(:proxy).command_line_template : nil
46
+ end
47
+
48
+ def keys
49
+ Array(ssh_option(:keys))
50
+ end
51
+
52
+ def ssh_cmd_args
53
+ args = []
54
+
55
+ args << '-t'
56
+ args << '-A' if forward_agent?
57
+ args << "-p #{port}" if port
58
+ args << "-l #{user}"
59
+ args << %Q{-o "ProxyCommand #{proxy_command}"} if proxy_command
60
+ args << %Q{-o "HostName #{host_name}"} if host_name
61
+
62
+ keys.each do |key|
63
+ args << "-i #{key}"
64
+ end
65
+
66
+ args
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ require 'capistrano/interactive/command'
2
+
3
+ module Capistrano
4
+ module Interactive
5
+ module DSL
6
+ def interact(*args)
7
+ Capistrano::Interactive::BackendHook.intercept_command!
8
+ execute(*args)
9
+ Capistrano::Interactive::Command.new(host, Capistrano::Interactive::BackendHook.last_command).execute
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Interactive
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'capistrano/interactive/dsl'
2
+ require 'capistrano/interactive/backend_hook'
3
+
4
+ SSHKit::Backend::Netssh.send(:include, Capistrano::Interactive::BackendHook)
5
+ include Capistrano::Interactive::DSL
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-interactive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Schwab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: sshkit
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.7.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.7.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.10'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description: Interactive command execution for capistrano
76
+ email:
77
+ - me@ydkn.de
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - capistrano-interactive.gemspec
90
+ - lib/capistrano/interactive.rb
91
+ - lib/capistrano/interactive/backend_hook.rb
92
+ - lib/capistrano/interactive/command.rb
93
+ - lib/capistrano/interactive/dsl.rb
94
+ - lib/capistrano/interactive/version.rb
95
+ homepage: https://github.com/ydkn/capistrano-interactive
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Interactive command execution for capistrano
119
+ test_files: []
120
+ has_rdoc: