cap-ssh-cmd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 000e0c748b9f27926b90d7f16a4d3123e0413a4d
4
+ data.tar.gz: f08675671b4a183528c15b277adb28ece3a8e2d3
5
+ SHA512:
6
+ metadata.gz: aefc475dd838ce6593efbc2bb77e2f5d25e7c272ff943b0e9ceed81b20163c9b5affbbddc352c0f759f3d4597a61eabefe0dda14f090d18125e46082ea101f11
7
+ data.tar.gz: 6360a6b6460295813e575164727824fff0c7c693ed467d0b996a0fd0f45bbdae615d7fd251e8d8246fedec365223235cefa9c0a4860c063a6f1bf3e93b45f4cf
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.14.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at adamluzsi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cap-ssh-cmd.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # Cap::Ssh::Cmd
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cap/ssh/cmd`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cap-ssh-cmd'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cap-ssh-cmd
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Adam Luzsi/cap-ssh-cmd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cap/ssh/cmd"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cap/ssh/cmd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = "cap-ssh-cmd"
9
+ spec.version = Cap::Ssh::Cmd::VERSION
10
+ spec.authors = ["Adam Luzsi"]
11
+ spec.email = ["adamluzsi@gmail.com"]
12
+
13
+ spec.summary = %q{Simple tool to use cap command to open ssh connection to a given server}
14
+ spec.description = %q{Simple tool to use cap command to open ssh connection to a given server}
15
+ spec.homepage = "https://github.com/adamluzsi/cap-ssh-cmd.rb"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+
29
+ end
@@ -0,0 +1,11 @@
1
+ require "cap/ssh/cmd/version"
2
+ if defined?(Capistrano::VERSION)
3
+ case Capistrano::VERSION
4
+ when /^2/
5
+ require(File.join(File.dirname(__FILE__),'cmd','2.rake'))
6
+ when /^3/
7
+ require(File.join(File.dirname(__FILE__),'cmd','2.rake'))
8
+ else
9
+ raise(NotImplementedError)
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ get_server_by_user = lambda do
2
+
3
+ list = [*find_servers_for_task(current_task)]
4
+ return list.first if list.length == 1
5
+
6
+ require 'io/console'
7
+
8
+ server = nil
9
+ $stdout.puts('Please choose a server address:')
10
+ list.each.with_index do |element, index|
11
+ $stdout.puts("\t#{index + 1}:\t#{element}")
12
+ end
13
+
14
+ loop do
15
+
16
+ begin
17
+
18
+ raw_input = $stdin.getch.chomp
19
+
20
+ exit(-1) if ["\x03", "\x04"].include?(raw_input)
21
+ raise("selected server id was not an integer (#{raw_input})") unless raw_input =~ /\d+/
22
+
23
+ chosen_index = raw_input.to_i - 1
24
+ server = list[chosen_index]
25
+
26
+ raise("Chosen server number is not valid: #{chosen_index + 1}") unless server
27
+ break
28
+
29
+ rescue => ex
30
+ $stdout.puts(ex.message)
31
+ end
32
+
33
+ end
34
+
35
+ return server
36
+
37
+ end
38
+
39
+ desc 'open ssh console'
40
+ task :ssh do
41
+ server ||= get_server_by_user.call()
42
+ exec "ssh #{user}@#{server.host}"
43
+ end
44
+
45
+ desc 'execute scp command, use ":" as begining to represent remote server address'
46
+ task :scp do
47
+ server ||= get_server_by_user.call()
48
+ args = [ARGV[-2], ARGV[-1]].map { |str| str.sub(/^:/, "#{user}@#{server.host}:") }
49
+ exec "scp #{args.join(' ')}"
50
+ end
@@ -0,0 +1,80 @@
1
+ class CapistranoSSH
2
+
3
+ def initialize(cap)
4
+ @cap = cap
5
+ end
6
+
7
+ def ssh
8
+ server = get_server_by_user
9
+ command = "ssh #{server.user}@#{[server.hostname, server.port].compact.join(':')}"
10
+ Kernel.exec(command)
11
+ end
12
+
13
+ def scp(argv)
14
+ server = get_server_by_user
15
+ args = [argv[-2], argv[-1]].map { |str| str.sub(/^:/, "#{server.user}@#{server.hostname}:") }
16
+ Kernel.exec("scp #{args.join(' ')}")
17
+ end
18
+
19
+ protected
20
+
21
+ def find_servers
22
+ servers = []
23
+ @cap.instance_exec do
24
+ on roles(:all) do |server|
25
+ servers << server # server hostname should be in here
26
+ end
27
+ end
28
+ return servers.sort_by{ |s| s.hostname }
29
+ end
30
+
31
+
32
+ def get_server_by_user
33
+
34
+ list = find_servers
35
+ return list.first if list.length == 1
36
+
37
+ require 'io/console'
38
+
39
+ server = nil
40
+ $stdout.puts('Please choose a server address:')
41
+ list.each.with_index do |element, index|
42
+ $stdout.puts("\t#{index + 1}:\t#{element}")
43
+ end
44
+
45
+ loop do
46
+
47
+ begin
48
+
49
+ raw_input = $stdin.getch.chomp
50
+
51
+ exit(-1) if ["\x03", "\x04"].include?(raw_input)
52
+ raise("selected server id was not an integer (#{raw_input})") unless raw_input =~ /\d+/
53
+
54
+ chosen_index = raw_input.to_i - 1
55
+ server = list[chosen_index]
56
+
57
+ raise("Chosen server number is not valid: #{chosen_index + 1}") unless server
58
+ break
59
+
60
+ rescue => ex
61
+ $stdout.puts(ex.message)
62
+ end
63
+
64
+ end
65
+
66
+ return server
67
+
68
+ end
69
+
70
+ end
71
+
72
+ desc 'open ssh console'
73
+ task :ssh do
74
+ CapistranoSSH.new(self).ssh
75
+ end
76
+
77
+ desc 'execute scp command, use ":" as begining to represent remote server address'
78
+ task :scp do
79
+ CapistranoSSH.new(self).scp(ARGV)
80
+ end
@@ -0,0 +1,7 @@
1
+ module Cap
2
+ module Ssh
3
+ module Cmd
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cap-ssh-cmd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Luzsi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Simple tool to use cap command to open ssh connection to a given server
56
+ email:
57
+ - adamluzsi@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - cap-ssh-cmd.gemspec
72
+ - lib/cap/ssh/cmd.rb
73
+ - lib/cap/ssh/cmd/2.rake
74
+ - lib/cap/ssh/cmd/3.rake
75
+ - lib/cap/ssh/cmd/version.rb
76
+ homepage: https://github.com/adamluzsi/cap-ssh-cmd.rb
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple tool to use cap command to open ssh connection to a given server
99
+ test_files: []