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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fulmar/shell.rb +22 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b1eecbc826fbdf7fb94816509ec2d7a21eb66ad
4
- data.tar.gz: 7eab24649e0767fe10006485d54cd0b23ed8e705
3
+ metadata.gz: 57c5684bfeaa62855b10e352b1f1dfed3b66da49
4
+ data.tar.gz: 7fa3c31d6c1a90521070f5fe3871396c65d6d82c
5
5
  SHA512:
6
- metadata.gz: bb282a8e9b650419a62981e5cca6eac1a219bd752a6b105e2ef8400dd98dd3951d9a7789b699b8b18adb69ec7d0a30f97b1adbd44e330c6bedf11ee0134c312e
7
- data.tar.gz: 57e25a5635a7bc7d765c11eccfb9fb6c0335051ec9a79bd045c9770c5ce4b7efb16f3873faf32c012e184a37044db6585f8e917f75934e9ed9263b470fc074d7
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.2.0'
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
- command.unshift "cd #{@path}"
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("sh -c '#{escape_for_sh(command.join(' && '))}'")
41
+ execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'")
29
42
  else
30
- remote_command = escape_for_sh('/bin/sh -c \'' + escape_for_sh(command.join(' && ')) + '\'')
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
- # DEBUG, baby!
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulmar-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerrit Visscher