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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a765a1decf65f3211a89fb0d0f64faa5a731f463b90e6e2bf7a4b3399b02f2bb
4
- data.tar.gz: ad56a45ee01b3397b2c1f45674ec7147c804454de8566da50751f5eece1937f1
3
+ metadata.gz: 9db87ce0fe83225ddc40e2b699957b8f1d3dd9a736865e5a43f4d1cdcd37d429
4
+ data.tar.gz: 0c9b65c4f1be9e553b572b8e75a6d3954b69e90af91adde800802c04978b2bb1
5
5
  SHA512:
6
- metadata.gz: 05e3085e88e721c09b3a8613f719a4634b7a77c6837b4a18354e6b1eae2620ac0779c5eab650569e68c533fe73c6dd558b8617b6161578feb63b7e22c65a1929
7
- data.tar.gz: b9c956477af17a1ea4cce829ef162132059c05336d89bd84863eff354db903a02331399ab15f8fb95b514638605cc5162ad91c1fcebff372d10796cceaa26e92
6
+ metadata.gz: d7be9b834c66b171c4dc56b843b51de47213e1e13c14106dd456800eae8a017ec08dc78b78c0ad9d9ff910bcfc6fba3e7883ecd1808e6736b6e0e89d6ae6a8b8
7
+ data.tar.gz: d3165d8d72eb52b2f13668da36f74cbf5ac55cf59db60682dd2f1434c21eeede46e509c053cd7862192b258e6b890c995bf87b2fd17ba3398d58e5085c7e99f1
data/.simplecov CHANGED
@@ -36,6 +36,6 @@ else
36
36
  SimpleCov.start do
37
37
  add_filter '/test/'
38
38
  add_filter '/features/'
39
- minimum_coverage 20
39
+ minimum_coverage 10
40
40
  end
41
41
  end
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
- until sout.eof?
88
- begin
89
- ln = sout.gets
90
- rescue IOError => e
91
- ln = Backtrace.new(e).to_s
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
- if log.nil?
94
- # no logging
95
- elsif log.respond_to?(mtd)
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.2.3'
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko