safe_shell 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/safe_shell.rb +8 -1
- data/lib/safe_shell/version.rb +1 -1
- data/spec/safe_shell_spec.rb +11 -0
- 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: 28bf046c92d72c7c144d67ea3f994b1d20feaed7
|
4
|
+
data.tar.gz: 699951038cd5fabbdf96548c2a550b6ee3ac191a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce82506dba7cb408292e2c1853091aef89d6ed8f0521894b4f76914f3fed8fd88aa5373cd5f1f4f598c0699e207d79e81baa071d0355f96ac7fc02f1321fa3c
|
7
|
+
data.tar.gz: 2038216ebe1151e36610ed5466fd51786a68ea7ee40f9c257ce4707b58c85b2d9495bc9b2820250645b93f514e5a81bbeee6259121581c5a781e531e44957b6d
|
data/README.md
CHANGED
@@ -23,6 +23,9 @@ SafeShell sets the $? operator to the process status, in the same manner as the
|
|
23
23
|
# Send stdout and stderr to files:
|
24
24
|
SafeShell.execute("echo", "Hello, world!", :stdout => "output.txt", :stderr => "error.txt")
|
25
25
|
|
26
|
+
# Send additional environment variables:
|
27
|
+
SafeShell.execute("echo", "Hello, world!", :env => { 'name' => 'john', 'foo' => 'bar' })
|
28
|
+
|
26
29
|
# Return true if the command exits with a zero status:
|
27
30
|
SafeShell.execute?("echo", "Hello, world!")
|
28
31
|
|
data/lib/safe_shell.rb
CHANGED
@@ -6,8 +6,15 @@ module SafeShell
|
|
6
6
|
read_end, write_end = IO.pipe
|
7
7
|
new_stdout = opts[:stdout] ? File.open(opts[:stdout], "w+") : write_end
|
8
8
|
new_stderr = opts[:stderr] ? File.open(opts[:stderr], "w+") : write_end
|
9
|
+
env = opts[:env]
|
9
10
|
opts = {:in => read_end, :out => new_stdout, :err => new_stderr}
|
10
|
-
|
11
|
+
|
12
|
+
pid = if env
|
13
|
+
spawn(env, command, *(args.map { |a| a.to_s }), opts)
|
14
|
+
else
|
15
|
+
spawn(command, *(args.map { |a| a.to_s }), opts)
|
16
|
+
end
|
17
|
+
|
11
18
|
write_end.close
|
12
19
|
output = read_end.read
|
13
20
|
Process.waitpid(pid)
|
data/lib/safe_shell/version.rb
CHANGED
data/spec/safe_shell_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'safe_shell'
|
2
|
+
require 'pathname'
|
2
3
|
|
3
4
|
describe "SafeShell" do
|
4
5
|
|
@@ -10,6 +11,16 @@ describe "SafeShell" do
|
|
10
11
|
expect(SafeShell.execute("echo", ";date")).to eql(";date\n")
|
11
12
|
end
|
12
13
|
|
14
|
+
it "allows to add new env vars" do
|
15
|
+
result = SafeShell.execute('env')
|
16
|
+
expect(result).to_not include("HELLO=world")
|
17
|
+
expect(result).to_not include("GOOD=world")
|
18
|
+
|
19
|
+
result = SafeShell.execute('env', env: {'HELLO' => 'world', 'GOOD' => 'day'})
|
20
|
+
expect(result).to include("HELLO=world")
|
21
|
+
expect(result).to include("GOOD=day")
|
22
|
+
end
|
23
|
+
|
13
24
|
it "should set $? to the exit status of the command" do
|
14
25
|
SafeShell.execute("test", "a", "=", "a")
|
15
26
|
expect($?.exitstatus).to eql(0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Envato
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.
|
72
|
+
rubygems_version: 2.5.1
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Safely execute shell commands and get their output.
|