fulmar-shell 1.5.2 → 1.6.0
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/lib/fulmar/shell.rb +29 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc5bb14a5ba3fd7793238ee0e27c9e5261d958f
|
4
|
+
data.tar.gz: e4266432900391b2580dcc65609f38daebf9f3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96cb5b258fdb9c2187bee07ab4b86c9fa65930acec3132a0eda2fa6507d535b60c15a1fbc392e1efe37140c85fad8fec1a4c63ebd4b33beb27c0b30f8ff0d3ef
|
7
|
+
data.tar.gz: 3b37acc54f5b39c6118dd1293b4d71ce2ad15890126eb25263f883e02a1a636876c14fe6e6de683f32d1890496f29440e23e0fdba91e86a7f9ba068b584c340b
|
data/lib/fulmar/shell.rb
CHANGED
@@ -5,11 +5,16 @@ require 'open3'
|
|
5
5
|
module Fulmar
|
6
6
|
# Implements simple access to shell commands
|
7
7
|
class Shell
|
8
|
-
VERSION = '1.
|
8
|
+
VERSION = '1.6.0'
|
9
9
|
|
10
10
|
attr_accessor :debug, :last_output, :last_error, :quiet, :strict
|
11
11
|
attr_reader :path
|
12
12
|
|
13
|
+
DEFAULT_OPTIONS = {
|
14
|
+
login: false,
|
15
|
+
bundler: true #
|
16
|
+
}
|
17
|
+
|
13
18
|
def initialize(path = '.', host = 'localhost')
|
14
19
|
@host = host
|
15
20
|
@path = (path.nil? || path.empty?) ? '.' : path
|
@@ -18,11 +23,11 @@ module Fulmar
|
|
18
23
|
@last_error = []
|
19
24
|
@debug = false
|
20
25
|
@quiet = false
|
21
|
-
@environment = {}
|
22
26
|
@strict = false
|
27
|
+
@clean_environment = [] # list of things to clean from environment variables
|
23
28
|
end
|
24
29
|
|
25
|
-
def run(command, options =
|
30
|
+
def run(command, options = DEFAULT_OPTIONS)
|
26
31
|
command = [command] if command.class == String
|
27
32
|
|
28
33
|
# is a custom path given?
|
@@ -38,7 +43,9 @@ module Fulmar
|
|
38
43
|
command.unshift "cd #{path}"
|
39
44
|
|
40
45
|
# invoke a login shell?
|
41
|
-
shell_command = options[:login]
|
46
|
+
shell_command = shell_command(options[:login])
|
47
|
+
|
48
|
+
@clean_environment << 'bundler' if options[:escape_bundler]
|
42
49
|
|
43
50
|
if local?
|
44
51
|
execute("#{shell_command} '#{escape_for_sh(command.join(' && '))}'", options[:error_message])
|
@@ -58,8 +65,23 @@ module Fulmar
|
|
58
65
|
|
59
66
|
protected
|
60
67
|
|
61
|
-
def
|
62
|
-
"env -i HOME=\"#{ENV['HOME']}\" LANG=\"#{ENV['LANG']}\" bash -lc"
|
68
|
+
def shell_command(login)
|
69
|
+
login ? "env -i HOME=\"#{ENV['HOME']}\" LANG=\"#{ENV['LANG']}\" bash -lc" : 'bash -c'
|
70
|
+
end
|
71
|
+
|
72
|
+
def environment
|
73
|
+
env = ENV.clone
|
74
|
+
if @clean_environment.include? 'bundler'
|
75
|
+
bundler_variable_parts = %w(ruby gem_ bundle)
|
76
|
+
# Remove any variables which contain the words above
|
77
|
+
env.delete_if { |key| bundler_variable_parts.select { |part| key.downcase.include?(part) }.any? }
|
78
|
+
env['PATH'] = path_without_bundler
|
79
|
+
end
|
80
|
+
env
|
81
|
+
end
|
82
|
+
|
83
|
+
def path_without_bundler
|
84
|
+
ENV['PATH'].split(':').reject { |path| path.include?('ruby') || path.include?('gems') }.join(':')
|
63
85
|
end
|
64
86
|
|
65
87
|
# Run the command and capture the output
|
@@ -67,7 +89,7 @@ module Fulmar
|
|
67
89
|
# Ladies and gentleman: More debug, please!
|
68
90
|
puts command if @debug
|
69
91
|
|
70
|
-
stdin, stdout, stderr, wait_thr = Open3.popen3(command)
|
92
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(environment, command)
|
71
93
|
|
72
94
|
# Remove annoying newlines at the end
|
73
95
|
@last_output = stdout.readlines.collect(&:chomp)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulmar-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerrit Visscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.4.5
|
76
|
+
rubygems_version: 2.4.5.1
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Small service to run shell commands on a local or remote shell
|