qbash 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/lib/qbash.rb +24 -16
- data/qbash.gemspec +1 -1
- data/test/test_qbash.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9db87ce0fe83225ddc40e2b699957b8f1d3dd9a736865e5a43f4d1cdcd37d429
|
4
|
+
data.tar.gz: 0c9b65c4f1be9e553b572b8e75a6d3954b69e90af91adde800802c04978b2bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7be9b834c66b171c4dc56b843b51de47213e1e13c14106dd456800eae8a017ec08dc78b78c0ad9d9ff910bcfc6fba3e7883ecd1808e6736b6e0e89d6ae6a8b8
|
7
|
+
data.tar.gz: d3165d8d72eb52b2f13668da36f74cbf5ac55cf59db60682dd2f1434c21eeede46e509c053cd7862192b258e6b890c995bf87b2fd17ba3398d58e5085c7e99f1
|
data/.simplecov
CHANGED
data/lib/qbash.rb
CHANGED
@@ -45,6 +45,10 @@ module Kernel
|
|
45
45
|
#
|
46
46
|
# Stderr automatically merges with stdout.
|
47
47
|
#
|
48
|
+
# If you need full control over the process started, provide
|
49
|
+
# a block, which will receive process ID (integer) once the process
|
50
|
+
# is started.
|
51
|
+
#
|
48
52
|
# Read this <a href="https://github.com/yegor256/qbash">README</a> file for more details.
|
49
53
|
#
|
50
54
|
# @param [String] cmd The command to run, for example +echo "Hello, world!"+
|
@@ -84,24 +88,28 @@ module Kernel
|
|
84
88
|
Open3.popen2e(env, "/bin/bash -c #{Shellwords.escape(cmd)}") do |sin, sout, thr|
|
85
89
|
sin.write(stdin)
|
86
90
|
sin.close
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
if block_given?
|
92
|
+
yield thr.pid
|
93
|
+
else
|
94
|
+
until sout.eof?
|
95
|
+
begin
|
96
|
+
ln = sout.gets
|
97
|
+
rescue IOError => e
|
98
|
+
ln = Backtrace.new(e).to_s
|
99
|
+
end
|
100
|
+
if log.nil?
|
101
|
+
# no logging
|
102
|
+
elsif log.respond_to?(mtd)
|
103
|
+
log.__send__(mtd, ln)
|
104
|
+
else
|
105
|
+
log.print("#{ln}\n")
|
106
|
+
end
|
107
|
+
buf += ln
|
92
108
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
log.__send__(mtd, ln)
|
97
|
-
else
|
98
|
-
log.print("#{ln}\n")
|
109
|
+
e = thr.value.to_i
|
110
|
+
if !accept.nil? && !accept.include?(e)
|
111
|
+
raise "The command '#{cmd}' failed with exit code ##{e} in #{start.ago}\n#{buf}"
|
99
112
|
end
|
100
|
-
buf += ln
|
101
|
-
end
|
102
|
-
e = thr.value.to_i
|
103
|
-
if !accept.nil? && !accept.include?(e)
|
104
|
-
raise "The command '#{cmd}' failed with exit code ##{e} in #{start.ago}\n#{buf}"
|
105
113
|
end
|
106
114
|
end
|
107
115
|
return [buf, e] if both
|
data/qbash.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=3.2'
|
28
28
|
s.name = 'qbash'
|
29
|
-
s.version = '0.
|
29
|
+
s.version = '0.3.0'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Quick Executor of a BASH Command'
|
32
32
|
s.description =
|
data/test/test_qbash.rb
CHANGED
@@ -96,6 +96,14 @@ class TestQbash < Minitest::Test
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
def test_kills_in_thread
|
100
|
+
Thread.new do
|
101
|
+
qbash('sleep 9999') do |pid|
|
102
|
+
Process.kill('KILL', pid)
|
103
|
+
end
|
104
|
+
end.join
|
105
|
+
end
|
106
|
+
|
99
107
|
def test_with_both
|
100
108
|
Dir.mktmpdir do |home|
|
101
109
|
stdout, code = qbash("cat #{Shellwords.escape(File.join(home, 'foo.txt'))}", accept: nil, both: true)
|