sshyguy 0.1.1 → 0.1.4
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 +4 -4
- data/Gemfile.lock +38 -0
- data/lib/data/example.json +31 -0
- data/lib/sshyguy/cli.rb +48 -0
- data/lib/sshyguy/command.rb +34 -0
- data/lib/sshyguy/config.rb +14 -0
- data/lib/sshyguy/core_ext.rb +34 -0
- data/lib/sshyguy/menu.rb +10 -0
- data/lib/sshyguy/prompt.rb +7 -0
- data/lib/sshyguy/screen.rb +31 -0
- data/lib/sshyguy/screens/folder_screen.rb +16 -0
- data/lib/sshyguy/screens/help_screen.rb +23 -0
- data/lib/sshyguy/screens/main_screen.rb +28 -0
- data/lib/sshyguy/screens/shortcut_screen.rb +16 -0
- data/lib/sshyguy/server.rb +47 -0
- data/lib/sshyguy/version.rb +1 -1
- data/sshyguy.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b1590c2e531aee0cfa9fa69356ceb0a394ee32e
|
4
|
+
data.tar.gz: 74579aa533c529aad6da88ce5e9aa0cce3f0f98c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf767fcc3f7d2c09a898f1f139c048fc9fe6989b58fd49dbad91e71af6b7eb0a39d833d675b61914f19eb9504c63f96ebdf5be8696edc74875c9b3b5f082ff54
|
7
|
+
data.tar.gz: bb03169c10c5f503c28e7605e4cd8bc270ff8f811e480f2d28b3f27f3f8e74d2d02aae82094e4bcf6843475935d6c92a7565ed8adf8bf386474a3dbf13756cea
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sshyguy (0.1)
|
5
|
+
tty-prompt
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
equatable (0.6.1)
|
11
|
+
necromancer (0.5.0)
|
12
|
+
pastel (0.7.3)
|
13
|
+
equatable (~> 0.6)
|
14
|
+
tty-color (~> 0.5)
|
15
|
+
rake (10.5.0)
|
16
|
+
tty-color (0.5.0)
|
17
|
+
tty-cursor (0.7.0)
|
18
|
+
tty-prompt (0.19.0)
|
19
|
+
necromancer (~> 0.5.0)
|
20
|
+
pastel (~> 0.7.0)
|
21
|
+
tty-reader (~> 0.6.0)
|
22
|
+
tty-reader (0.6.0)
|
23
|
+
tty-cursor (~> 0.7)
|
24
|
+
tty-screen (~> 0.7)
|
25
|
+
wisper (~> 2.0.0)
|
26
|
+
tty-screen (0.7.0)
|
27
|
+
wisper (2.0.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 2.0)
|
34
|
+
rake (~> 10.0)
|
35
|
+
sshyguy!
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.0.2
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"config": {
|
3
|
+
"debug": false,
|
4
|
+
"include_shortcut": true,
|
5
|
+
"cycle": true,
|
6
|
+
"filter": true,
|
7
|
+
"editor": "subl",
|
8
|
+
"folders": true,
|
9
|
+
"ssh_defaults": {
|
10
|
+
"user": "root",
|
11
|
+
"port": 22
|
12
|
+
}
|
13
|
+
},
|
14
|
+
"servers": [
|
15
|
+
{
|
16
|
+
"hostname": "192.168.0.123",
|
17
|
+
"port": "60301",
|
18
|
+
"user": "deploy",
|
19
|
+
"label": "Production",
|
20
|
+
"shortcut": "production",
|
21
|
+
"folder": "Default",
|
22
|
+
"options": "-L 8888:192.168.1.111:1234"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"hostname": "",
|
26
|
+
"user": "",
|
27
|
+
"label": "",
|
28
|
+
"command": ""
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
data/lib/sshyguy/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'sshyguy/screen'
|
2
|
+
require 'sshyguy/screens/help_screen'
|
3
|
+
require 'sshyguy/screens/main_screen'
|
4
|
+
require 'sshyguy/screens/shortcut_screen'
|
5
|
+
require 'sshyguy/screens/folder_screen'
|
6
|
+
|
7
|
+
module SshyGuy
|
8
|
+
class CLI
|
9
|
+
def self.run
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: sshy [options]"
|
13
|
+
|
14
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
15
|
+
options[:verbose] = v
|
16
|
+
end
|
17
|
+
opts.on("-h", "--help", "Help") do |v|
|
18
|
+
options[:help] = true
|
19
|
+
end
|
20
|
+
opts.on("-s", "--shortcut", "Shortcut") do |v|
|
21
|
+
options[:shortcut] = v
|
22
|
+
end
|
23
|
+
opts.on('--install') do |v|
|
24
|
+
options[:install] = true
|
25
|
+
end
|
26
|
+
end.parse!
|
27
|
+
new(options).run
|
28
|
+
end
|
29
|
+
attr_reader :options
|
30
|
+
def initialize(options = {})
|
31
|
+
@options = options
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
if options[:install]
|
36
|
+
puts "Writing to #{SshyGuy.config_file}"
|
37
|
+
File.open(SshyGuy.config_file, "w+") { |f| f.puts(File.read("lib/data/example.json")) }
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
SshyGuy.load_config!
|
41
|
+
if options[:help]
|
42
|
+
Screens::HelpScreen.show(options)
|
43
|
+
else
|
44
|
+
Screens::MainScreen.show(options)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
class Command
|
3
|
+
attr_reader :to_command
|
4
|
+
def initialize(config)
|
5
|
+
@config = config
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_command
|
9
|
+
if @config['command'].present?
|
10
|
+
@config['command']
|
11
|
+
else
|
12
|
+
parts = ["ssh"]
|
13
|
+
if @config['options'].present?
|
14
|
+
parts << @config['options']
|
15
|
+
end
|
16
|
+
parts << "#{user}@#{hostname}"
|
17
|
+
parts << "-p #{port}"
|
18
|
+
parts.join(" ")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def hostname
|
23
|
+
@config['hostname'] || SshyGuy.config.ssh_defaults['hostname']
|
24
|
+
end
|
25
|
+
|
26
|
+
def user
|
27
|
+
@config['user'].presence || SshyGuy.config.ssh_defaults['user']
|
28
|
+
end
|
29
|
+
|
30
|
+
def port
|
31
|
+
@config['port'].presence || SshyGuy.config.ssh_defaults['port']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class NilClass
|
2
|
+
def presence
|
3
|
+
false
|
4
|
+
end
|
5
|
+
def present?
|
6
|
+
false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class String
|
11
|
+
def presence
|
12
|
+
present? ? self : false
|
13
|
+
end
|
14
|
+
def present?
|
15
|
+
!empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class FalseClass
|
20
|
+
def presence
|
21
|
+
false
|
22
|
+
end
|
23
|
+
def present?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class TrueClass
|
28
|
+
def presence
|
29
|
+
true
|
30
|
+
end
|
31
|
+
def present?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
data/lib/sshyguy/menu.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
class Screen
|
3
|
+
def self.show(options)
|
4
|
+
new(options).show
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :prompt, :options
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
@prompt = Prompt.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def current_folder
|
20
|
+
@current_folder ||= SshyGuy.params[:folder].presence
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_folder?
|
24
|
+
current_folder.present? && current_folder != "__ALL"
|
25
|
+
end
|
26
|
+
|
27
|
+
def params
|
28
|
+
SshyGuy.params
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
module Screens
|
3
|
+
class FolderScreen < Screen
|
4
|
+
def show
|
5
|
+
selected = prompt.select("Select a folder") do |select|
|
6
|
+
Server.folders.each do |folder|
|
7
|
+
select.choice(folder)
|
8
|
+
end
|
9
|
+
select.choice("All servers", "__ALL")
|
10
|
+
end
|
11
|
+
SshyGuy.params[:folder] = selected
|
12
|
+
MainScreen.show(options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
module Screens
|
3
|
+
class HelpScreen < Screen
|
4
|
+
def show
|
5
|
+
selection = prompt.select("How can I help?") do |select|
|
6
|
+
select.enum '.'
|
7
|
+
select.choice("Edit config file", :edit)
|
8
|
+
select.choice("Jk", :close)
|
9
|
+
select.choice("Exit", :exit)
|
10
|
+
end
|
11
|
+
case selection
|
12
|
+
when :edit
|
13
|
+
system("#{SshyGuy.config.editor} #{SshyGuy.config_file}")
|
14
|
+
exit
|
15
|
+
when :exit
|
16
|
+
puts "Bye."
|
17
|
+
exit
|
18
|
+
when :close
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
module Screens
|
3
|
+
class MainScreen < Screen
|
4
|
+
def show
|
5
|
+
if SshyGuy.params[:folder] && SshyGuy.params[:folder] != "__ALL"
|
6
|
+
servers = SshyGuy::Server.all.select { |server| server.folder == params[:folder] }
|
7
|
+
label = "Select a server from #{SshyGuy.params[:folder]}."
|
8
|
+
else
|
9
|
+
label = "Select a server."
|
10
|
+
servers = SshyGuy::Server.all
|
11
|
+
end
|
12
|
+
server = prompt.select(label, cycle: SshyGuy.config.cycle?, filter: SshyGuy.config.filter?) do |select|
|
13
|
+
select.enum '.'
|
14
|
+
servers.each do |item|
|
15
|
+
select.choice(item.to_label, item)
|
16
|
+
end
|
17
|
+
select.choice("Exit folder", :close_folder) if current_folder?
|
18
|
+
end
|
19
|
+
if server == :close_folder
|
20
|
+
SshyGuy.params[:folder] = '__ALL'
|
21
|
+
MainScreen.show(options)
|
22
|
+
else
|
23
|
+
server.spawn
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
module Screens
|
3
|
+
class ShortcutScreen < Screen
|
4
|
+
def show
|
5
|
+
menu = Menu.new
|
6
|
+
shortcut = menu.items.detect { |item| item.shortcut == args[:shortcut] }
|
7
|
+
unless shortcut
|
8
|
+
puts "No shortcut found for '#{args[:shortcut]}'"
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
shortcut.spawn
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SshyGuy
|
2
|
+
class Server
|
3
|
+
def self.all
|
4
|
+
@all ||= []
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.build(servers)
|
8
|
+
servers.each do |server|
|
9
|
+
self.all << Server.new(server)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.folders
|
14
|
+
@folders ||= self.all.map(&:folder).uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(config)
|
18
|
+
@config = config
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_label
|
22
|
+
@config['label'] || @config['hostname']
|
23
|
+
end
|
24
|
+
|
25
|
+
def spawn
|
26
|
+
SshyGuy.log("Spawning command #{command.to_command}")
|
27
|
+
system(command.to_command)
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
def command
|
32
|
+
@command ||= Command.new(@config)
|
33
|
+
end
|
34
|
+
|
35
|
+
def folder
|
36
|
+
@config['folder'].presence || "Default"
|
37
|
+
end
|
38
|
+
|
39
|
+
def shortcut
|
40
|
+
@config['shortcut'].presence
|
41
|
+
end
|
42
|
+
|
43
|
+
def group
|
44
|
+
@config['group'].presence || "Default"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/sshyguy/version.rb
CHANGED
data/sshyguy.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshyguy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Brody
|
@@ -62,12 +62,26 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- Gemfile
|
65
|
+
- Gemfile.lock
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- bin/console
|
68
69
|
- bin/setup
|
69
70
|
- bin/sshyguy
|
71
|
+
- lib/data/example.json
|
70
72
|
- lib/sshyguy.rb
|
73
|
+
- lib/sshyguy/cli.rb
|
74
|
+
- lib/sshyguy/command.rb
|
75
|
+
- lib/sshyguy/config.rb
|
76
|
+
- lib/sshyguy/core_ext.rb
|
77
|
+
- lib/sshyguy/menu.rb
|
78
|
+
- lib/sshyguy/prompt.rb
|
79
|
+
- lib/sshyguy/screen.rb
|
80
|
+
- lib/sshyguy/screens/folder_screen.rb
|
81
|
+
- lib/sshyguy/screens/help_screen.rb
|
82
|
+
- lib/sshyguy/screens/main_screen.rb
|
83
|
+
- lib/sshyguy/screens/shortcut_screen.rb
|
84
|
+
- lib/sshyguy/server.rb
|
71
85
|
- lib/sshyguy/version.rb
|
72
86
|
- sshyguy.gemspec
|
73
87
|
homepage: https://github.com/joshmn/sshyguy
|