fulmar-shell 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fulmar/shell.rb +22 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c5684bfeaa62855b10e352b1f1dfed3b66da49
|
4
|
+
data.tar.gz: 7fa3c31d6c1a90521070f5fe3871396c65d6d82c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aeca2e5686ef2d93f4a520db37a0170000c43d4849a08f8e7f7775ecba5b4cf96688386fe98cdf2d0b7c7f19116408e40d1d800cb339fab5fd6479e782b442f
|
7
|
+
data.tar.gz: a2a915681e357b0302ce6ae6a1f9e876dd80e142612a9cf9fb9940dbf269bd79adbd7bece130212842a5d16379b92bc7816bc56c65532866c959f36f1d612b3b
|
data/lib/fulmar/shell.rb
CHANGED
@@ -5,29 +5,42 @@ require 'open3'
|
|
5
5
|
module Fulmar
|
6
6
|
# Implements simple access to shell commands
|
7
7
|
class Shell
|
8
|
-
VERSION = '1.
|
8
|
+
VERSION = '1.3.0'
|
9
9
|
|
10
10
|
attr_accessor :debug, :last_output, :last_error, :quiet
|
11
11
|
attr_reader :path
|
12
12
|
|
13
|
-
def initialize(path, host = 'localhost')
|
14
|
-
@path = File.expand_path((path.nil? || path.empty?) ? '.' : path)
|
13
|
+
def initialize(path = '.', host = 'localhost')
|
15
14
|
@host = host
|
15
|
+
@path = (path.nil? || path.empty?) ? '.' : path
|
16
|
+
@path = File.expand_path(@path) if local?
|
16
17
|
@last_output = []
|
17
18
|
@last_error = []
|
18
19
|
@debug = false
|
19
20
|
@quiet = false
|
21
|
+
@environment = {}
|
20
22
|
end
|
21
23
|
|
22
|
-
def run(command)
|
24
|
+
def run(command, options = {})
|
23
25
|
command = [command] if command.class == String
|
24
26
|
|
25
|
-
|
27
|
+
# is a custom path given?
|
28
|
+
if options[:in]
|
29
|
+
# is it absolute?
|
30
|
+
path = options[:in][0, 1] == '/' ? options[:in] : "#{@path}/#{options[:in]}"
|
31
|
+
else
|
32
|
+
path = @path
|
33
|
+
end
|
34
|
+
|
35
|
+
command.unshift "cd #{path}"
|
36
|
+
|
37
|
+
# invoke a login shell?
|
38
|
+
shell_command = options[:login] ? 'env -i bash -lc' : 'bash -c'
|
26
39
|
|
27
40
|
if local?
|
28
|
-
execute("
|
41
|
+
execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
|
29
42
|
else
|
30
|
-
remote_command = escape_for_sh(
|
43
|
+
remote_command = escape_for_sh("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
|
31
44
|
execute("ssh #{@host} '#{remote_command}'")
|
32
45
|
end
|
33
46
|
end
|
@@ -37,14 +50,14 @@ module Fulmar
|
|
37
50
|
end
|
38
51
|
|
39
52
|
def path=(path)
|
40
|
-
@path = File.expand_path(path)
|
53
|
+
@path = local? ? File.expand_path(path) : path
|
41
54
|
end
|
42
55
|
|
43
56
|
protected
|
44
57
|
|
45
58
|
# Run the command and capture the output
|
46
59
|
def execute(command)
|
47
|
-
#
|
60
|
+
# Ladies and gentleman: More debug, please!
|
48
61
|
puts command if @debug
|
49
62
|
|
50
63
|
stdin, stdout, stderr, wait_thr = Open3.popen3(command)
|