jossh 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -31
- data/lib/jossh/api.rb +8 -1
- data/lib/jossh/bin_handler.rb +18 -2
- data/lib/jossh/command_runner.rb +25 -7
- data/lib/jossh/templates/docopt.txt +2 -0
- data/lib/jossh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3857009678775cc0439cfbc76d384550da761b35
|
4
|
+
data.tar.gz: bea78d4e9600dfb3d87b589c7529cbfe2a9ac071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb2711d5f7ca8ad17daf52d042a16d2590c5b182d2a0ad237b6f01a4bf8672f2a5923d2946837a169cbbb2cc899237e6b5640ce16b569c6ca8bd0ac74b6c2c28
|
7
|
+
data.tar.gz: f5108787af8a0048589d0503810113028672d20fb3fa58565302746114c68dcea8e50b85dd7de03fb89f53c3c7727f048e70f3482fc6920de1cf2034308522f6
|
data/README.md
CHANGED
@@ -39,41 +39,40 @@ Or install manually
|
|
39
39
|
After installing, you can call `jossh` from the command line to run arbitrary
|
40
40
|
commands or a local script over SSH.
|
41
41
|
|
42
|
-
|
43
|
-
$ jossh -h
|
44
|
-
|
45
|
-
Jossh
|
42
|
+
$ jossh -h
|
46
43
|
|
47
|
-
|
48
|
-
jossh <host> <script>
|
49
|
-
jossh -m | --make-hostfile
|
50
|
-
jossh -h | --help
|
51
|
-
jossh -v | --version
|
44
|
+
Jossh
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
Usage:
|
47
|
+
jossh <host> <script>
|
48
|
+
jossh -m | --make-hostfile
|
49
|
+
jossh -l | --list
|
50
|
+
jossh -h | --help
|
51
|
+
jossh -v | --version
|
59
52
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
53
|
+
Arguments:
|
54
|
+
<host>
|
55
|
+
can be:
|
56
|
+
- :symbol : in this case we will look in ./ssh_hosts.yml
|
57
|
+
- host : in this case we will use the current logged in user
|
58
|
+
- user@host
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
<script>
|
61
|
+
can be:
|
62
|
+
- a filename
|
63
|
+
- one or more direct command
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
Options:
|
66
|
+
-m --make-hostfile Generate a template ssh_hosts.yml
|
67
|
+
-l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
|
68
|
+
-h --help Show this screen
|
69
|
+
-v --version Show version
|
74
70
|
|
71
|
+
Examples:
|
72
|
+
jossh :production "git status"
|
73
|
+
jossh jack@server.com "cd ~ && ls -l"
|
74
|
+
jossh server.com deploy
|
75
75
|
|
76
|
-
```
|
77
76
|
|
78
77
|
## Library Usage
|
79
78
|
|
@@ -132,12 +131,21 @@ See also: The [examples folder](https://github.com/DannyBen/jossh/tree/master/ex
|
|
132
131
|
|
133
132
|
## Host specification file
|
134
133
|
|
135
|
-
|
134
|
+
When using a :symbol as the host name, Jossh will look for a YAML
|
135
|
+
configuration file named `ssh_hosts.yml`. The file is expected to be either
|
136
|
+
in the current directory or the user's home directory.
|
136
137
|
|
137
|
-
If you wish to use a different location, use the `ssh_hostfile`
|
138
|
+
If you wish to use a different filename or location, use the `ssh_hostfile`
|
139
|
+
method. If you specify only a filename or a relative path, Jossh will still
|
140
|
+
look for this file in both the current directory and user's home directory.
|
138
141
|
|
139
142
|
```ruby
|
140
|
-
|
143
|
+
# Specify exact location
|
144
|
+
ssh_hostfile "/etc/my_hosts.yml"
|
145
|
+
ssh! :myhost, 'ls'
|
146
|
+
|
147
|
+
# Look for ./configs/hosts.yml or ~/configs/hosts.yml
|
148
|
+
ssh_hostfile "configs/hosts.yml"
|
141
149
|
ssh! :myhost, 'ls'
|
142
150
|
```
|
143
151
|
|
data/lib/jossh/api.rb
CHANGED
@@ -26,7 +26,7 @@ module Jossh
|
|
26
26
|
#
|
27
27
|
# ssh { host: 'localhost', user: 'vagrant' }, "ls -l"
|
28
28
|
#
|
29
|
-
# def my_puts(data)
|
29
|
+
# def my_puts(data, stream)
|
30
30
|
# puts "> #{data}"
|
31
31
|
# end
|
32
32
|
# ssh :localhost, "ls -l", method: my_puts
|
@@ -73,6 +73,13 @@ module Jossh
|
|
73
73
|
CommandRunner.instance.ssh_script! hostspec, script
|
74
74
|
end
|
75
75
|
|
76
|
+
# Set the name of the hostfile
|
77
|
+
#
|
78
|
+
# ==== Params:
|
79
|
+
#
|
80
|
+
# +file+::
|
81
|
+
# Path to a YAML file
|
82
|
+
#
|
76
83
|
def ssh_hostfile(file)
|
77
84
|
CommandRunner.instance.ssh_hostfile file
|
78
85
|
end
|
data/lib/jossh/bin_handler.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'etc'
|
2
2
|
require 'docopt'
|
3
|
+
require 'colsole'
|
3
4
|
require 'fileutils'
|
4
5
|
|
5
6
|
module Jossh
|
6
7
|
|
7
8
|
class BinHandler
|
8
9
|
|
10
|
+
include Colsole
|
11
|
+
|
9
12
|
def handle(args)
|
10
13
|
begin
|
11
14
|
execute Docopt::docopt(doc, argv: args)
|
@@ -17,8 +20,9 @@ module Jossh
|
|
17
20
|
private
|
18
21
|
|
19
22
|
def execute(args)
|
20
|
-
return make_hostfile if args['--make-hostfile']
|
21
23
|
return show_version if args['--version']
|
24
|
+
return make_hostfile if args['--make-hostfile']
|
25
|
+
return list_hosts if args['--list']
|
22
26
|
handle_script args['<host>'].dup, args['<script>']
|
23
27
|
end
|
24
28
|
|
@@ -58,7 +62,19 @@ module Jossh
|
|
58
62
|
abort "ssh_hosts.yml already exists" if File.exist?('ssh_hosts.yml')
|
59
63
|
FileUtils.copy template('ssh_hosts.yml'), './ssh_hosts.yml'
|
60
64
|
File.exist? './ssh_hosts.yml' or abort "Unable to create ssh_hosts.yml"
|
61
|
-
|
65
|
+
say "!txtgrn!Created ssh_hosts.yml"
|
66
|
+
end
|
67
|
+
|
68
|
+
def list_hosts
|
69
|
+
runner = CommandRunner.new
|
70
|
+
if runner.active_hostfile
|
71
|
+
say "!txtgrn!Using: #{runner.active_hostfile}\n"
|
72
|
+
runner.ssh_hosts.each do |key, spec|
|
73
|
+
say " :#{key.to_s.ljust(14)} = !txtblu!#{spec[:user]}!txtrst!@!txtylw!#{spec[:host]}"
|
74
|
+
end
|
75
|
+
else
|
76
|
+
say "!txtred!Cannot find ssh_hosts.yml or ~/ssh_hosts.yml"
|
77
|
+
end
|
62
78
|
end
|
63
79
|
|
64
80
|
def show_version
|
data/lib/jossh/command_runner.rb
CHANGED
@@ -39,6 +39,7 @@ module Jossh
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def ssh_hostfile(file)
|
42
|
+
file = 'ssh_hosts.yml' if file == :default
|
42
43
|
@hostfile = file
|
43
44
|
|
44
45
|
# force reload in case we were called after some ssh call was
|
@@ -46,6 +47,20 @@ module Jossh
|
|
46
47
|
@ssh_hosts = nil
|
47
48
|
end
|
48
49
|
|
50
|
+
def ssh_hosts
|
51
|
+
@ssh_hosts ||= load_ssh_hosts
|
52
|
+
end
|
53
|
+
|
54
|
+
def active_hostfile
|
55
|
+
if File.exist? hostfile
|
56
|
+
hostfile
|
57
|
+
elsif hostfile[0] != '/' and File.exist? user_hostfile
|
58
|
+
user_hostfile
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
49
64
|
private
|
50
65
|
|
51
66
|
def simple_puts(data, stream)
|
@@ -57,22 +72,25 @@ module Jossh
|
|
57
72
|
end
|
58
73
|
|
59
74
|
def load_spec(key)
|
60
|
-
ssh_hosts[key] or raise "Cannot find :#{key}
|
61
|
-
end
|
62
|
-
|
63
|
-
def ssh_hosts
|
64
|
-
@ssh_hosts ||= load_ssh_hosts
|
75
|
+
ssh_hosts[key] or raise "Cannot find :#{key}"
|
65
76
|
end
|
66
77
|
|
67
78
|
def load_ssh_hosts
|
68
|
-
|
69
|
-
|
79
|
+
if active_hostfile
|
80
|
+
YAML.load_file active_hostfile
|
81
|
+
else
|
82
|
+
raise "Cannot find #{hostfile} or #{user_hostfile}"
|
83
|
+
end
|
70
84
|
end
|
71
85
|
|
72
86
|
def hostfile
|
73
87
|
@hostfile ||= 'ssh_hosts.yml'
|
74
88
|
end
|
75
89
|
|
90
|
+
def user_hostfile
|
91
|
+
"#{Dir.home}/#{hostfile}"
|
92
|
+
end
|
93
|
+
|
76
94
|
def load_script(script)
|
77
95
|
File.read script
|
78
96
|
end
|
@@ -3,6 +3,7 @@ Jossh
|
|
3
3
|
Usage:
|
4
4
|
jossh <host> <script>
|
5
5
|
jossh -m | --make-hostfile
|
6
|
+
jossh -l | --list
|
6
7
|
jossh -h | --help
|
7
8
|
jossh -v | --version
|
8
9
|
|
@@ -20,6 +21,7 @@ Arguments:
|
|
20
21
|
|
21
22
|
Options:
|
22
23
|
-m --make-hostfile Generate a template ssh_hosts.yml
|
24
|
+
-l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
|
23
25
|
-h --help Show this screen
|
24
26
|
-v --version Show version
|
25
27
|
|
data/lib/jossh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jossh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|