jossh 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3857009678775cc0439cfbc76d384550da761b35
4
- data.tar.gz: bea78d4e9600dfb3d87b589c7529cbfe2a9ac071
3
+ metadata.gz: 7d18b383a8d45121c2f64df1ac726857fb44096d
4
+ data.tar.gz: bebcc43c96495901ff70c46b906e7fbd51bdf177
5
5
  SHA512:
6
- metadata.gz: bb2711d5f7ca8ad17daf52d042a16d2590c5b182d2a0ad237b6f01a4bf8672f2a5923d2946837a169cbbb2cc899237e6b5640ce16b569c6ca8bd0ac74b6c2c28
7
- data.tar.gz: f5108787af8a0048589d0503810113028672d20fb3fa58565302746114c68dcea8e50b85dd7de03fb89f53c3c7727f048e70f3482fc6920de1cf2034308522f6
6
+ metadata.gz: b3a456a8f5468b9384b0087b03d25e2e3b660536df1d6a16e62e0c5fd2a72b5f9caf2aba8a5272f723b8e6a4de9e7cdb26031da3da0cd55065a313063921d043
7
+ data.tar.gz: b43df4b36e426cfd037902654d79c20388988484a1e1c922e4c9d7c25884277e9201b99bbd1b8b2a39aeb0d01014ad536a506c22ac1ef9821b0a08783fdf712a
data/README.md CHANGED
@@ -44,7 +44,7 @@ commands or a local script over SSH.
44
44
  Jossh
45
45
 
46
46
  Usage:
47
- jossh <host> <script>
47
+ jossh <host> <script> [-- <arguments>...]
48
48
  jossh -m | --make-hostfile
49
49
  jossh -l | --list
50
50
  jossh -h | --help
@@ -62,6 +62,12 @@ commands or a local script over SSH.
62
62
  - a filename
63
63
  - one or more direct command
64
64
 
65
+ <arguments>...
66
+ When specifying a filename as the <script>, you may also pass additional
67
+ arguments to it.
68
+ Use $1 - $9 in your script file to work with these arguments.
69
+ Use $@ (or $*) to use the entire arguments string
70
+
65
71
  Options:
66
72
  -m --make-hostfile Generate a template ssh_hosts.yml
67
73
  -l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
@@ -72,6 +78,7 @@ commands or a local script over SSH.
72
78
  jossh :production "git status"
73
79
  jossh jack@server.com "cd ~ && ls -l"
74
80
  jossh server.com deploy
81
+ jossh server.com rake -- db:migrate
75
82
 
76
83
 
77
84
  ## Library Usage
data/lib/jossh/api.rb CHANGED
@@ -61,16 +61,16 @@ module Jossh
61
61
  #
62
62
  # ssh_script :localhost, "deploy"
63
63
  #
64
- def ssh_script(hostspec, script, callback: nil)
65
- CommandRunner.instance.ssh_script hostspec, script, callback: callback
64
+ def ssh_script(hostspec, script, arguments: nil, callback: nil)
65
+ CommandRunner.instance.ssh_script hostspec, script, arguments: arguments, callback: callback
66
66
  end
67
67
 
68
68
  # Same as +ssh_script+, only this will print a pretty output.
69
69
  #
70
70
  # This method accepts only +hostspec+ and +script+ (no +callback+).
71
71
  #
72
- def ssh_script!(hostspec, script)
73
- CommandRunner.instance.ssh_script! hostspec, script
72
+ def ssh_script!(hostspec, script, arguments: nil)
73
+ CommandRunner.instance.ssh_script! hostspec, script, arguments: arguments
74
74
  end
75
75
 
76
76
  # Set the name of the hostfile
@@ -23,15 +23,15 @@ module Jossh
23
23
  return show_version if args['--version']
24
24
  return make_hostfile if args['--make-hostfile']
25
25
  return list_hosts if args['--list']
26
- handle_script args['<host>'].dup, args['<script>']
26
+ handle_script args['<host>'].dup, args['<script>'], arguments: args['<arguments>']
27
27
  end
28
28
 
29
- def handle_script(host, script)
29
+ def handle_script(host, script, arguments: nil)
30
30
  host = standardize_host host
31
31
 
32
32
  begin
33
33
  if File.exist? script
34
- ssh_script! host, script
34
+ ssh_script! host, script, arguments: arguments
35
35
  else
36
36
  ssh host, script
37
37
  end
@@ -30,12 +30,12 @@ module Jossh
30
30
  end
31
31
  end
32
32
 
33
- def ssh_script!(hostspec, script)
34
- ssh! hostspec, load_script(script)
33
+ def ssh_script!(hostspec, script, arguments: nil)
34
+ ssh! hostspec, load_script(script, arguments)
35
35
  end
36
36
 
37
- def ssh_script(hostspec, script, callback: nil)
38
- ssh hostspec, load_script(script), callback: callback
37
+ def ssh_script(hostspec, script, arguments: nil, callback: nil)
38
+ ssh hostspec, load_script(script, arguments), callback: callback
39
39
  end
40
40
 
41
41
  def ssh_hostfile(file)
@@ -91,11 +91,18 @@ module Jossh
91
91
  "#{Dir.home}/#{hostfile}"
92
92
  end
93
93
 
94
- def load_script(script)
95
- File.read script
94
+ def load_script(script, arguments=nil)
95
+ evaluate_args File.read(script), arguments
96
+ end
97
+
98
+ def evaluate_args(string, arguments)
99
+ return string unless arguments.is_a? Array and !arguments.empty?
100
+ all_arguments = arguments.map{|a| a =~ /\s/ ? "\"#{a}\"" : a}.join ' '
101
+ string.gsub!(/\$(\d)/) { arguments[$1.to_i - 1] }
102
+ string.gsub!(/\$[*|@]/, all_arguments)
103
+ string
96
104
  end
97
105
 
98
106
  end
99
107
 
100
108
  end
101
-
@@ -1,7 +1,7 @@
1
1
  Jossh
2
2
 
3
3
  Usage:
4
- jossh <host> <script>
4
+ jossh <host> <script> [-- <arguments>...]
5
5
  jossh -m | --make-hostfile
6
6
  jossh -l | --list
7
7
  jossh -h | --help
@@ -19,6 +19,12 @@ Arguments:
19
19
  - a filename
20
20
  - one or more direct command
21
21
 
22
+ <arguments>...
23
+ When specifying a filename as the <script>, you may also pass additional
24
+ arguments to it.
25
+ Use $1 - $9 in your script file to work with these arguments.
26
+ Use $@ (or $*) to use the entire arguments string
27
+
22
28
  Options:
23
29
  -m --make-hostfile Generate a template ssh_hosts.yml
24
30
  -l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
@@ -29,4 +35,5 @@ Examples:
29
35
  jossh :production "git status"
30
36
  jossh jack@server.com "cd ~ && ls -l"
31
37
  jossh server.com deploy
38
+ jossh server.com rake -- db:migrate
32
39
 
data/lib/jossh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jossh
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
4
+ version: 0.1.4
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-28 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole