qbash 0.3.2 → 0.4.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: 99ee7da1c86261e9e775fcf93c0d13de3393d9a861b3e30598b23509e97e80f6
4
- data.tar.gz: 7e6cfe10c543dccf59e2b1aa7d36890a539d2cb72c00d041c949611d2a2344dd
3
+ metadata.gz: 0b0f67b4e45883bc237c70115187e6ab211f6fdd29da3f9f891720153ad26569
4
+ data.tar.gz: a12f5e499c7f756d71c59b52467454346c455e72d291d2bae7891f05c7e8610b
5
5
  SHA512:
6
- metadata.gz: b8a978fd448871257f511cd0dfd14459e1da2837a948033069a4bd11b029f5fb9501eff131adea19000005057f5474ecc8264cfa8ce2e6cb3aa5eaddcda6b2ea
7
- data.tar.gz: 7ea6c3330923bccbadbdeae609730573e20022fdc3a888bcd8095c40c11ae583819080c6c11778a513eb4c6c51f73474434d5a7ce66836cb85826d257510cc1b
6
+ metadata.gz: eb17f8adf645e156986fcf7d08b27ee3b049fa29910b1f7b9154c51339530481167419d2a68af21b9dafae51613f81971b3e6e30f5eb175416ddafb82c87ea6b
7
+ data.tar.gz: 55c6932d3ff9a02474c33d69b3fa05f0b3ae83bf36a911468c155ef3944b603a9dceb29b13ba04eea3e9f3bd8748e90101952b0586d0e82001229a398d80c555
data/.rubocop.yml CHANGED
@@ -31,7 +31,6 @@ require:
31
31
  - rubocop-minitest
32
32
  - rubocop-performance
33
33
  - rubocop-rake
34
-
35
34
  Minitest/EmptyLineBeforeAssertionMethods:
36
35
  Enabled: false
37
36
  Metrics/ParameterLists:
data/Gemfile CHANGED
@@ -29,7 +29,7 @@ gem 'minitest-reporters', '1.7.1', require: false
29
29
  gem 'net-ping', '2.0.8', require: false
30
30
  gem 'rake', '13.2.1', require: false
31
31
  gem 'random-port', '~>0.0', require: false
32
- gem 'rspec-rails', '7.1.0', require: false
32
+ gem 'rspec-rails', '7.1.1', require: false
33
33
  gem 'rubocop', '1.71.2', require: false
34
34
  gem 'rubocop-minitest', '0.36.0', require: false
35
35
  gem 'rubocop-performance', '1.23.1', require: false
@@ -38,5 +38,5 @@ gem 'rubocop-rspec', '3.4.0', require: false
38
38
  gem 'simplecov', '0.22.0', require: false
39
39
  gem 'simplecov-cobertura', '2.1.0', require: false
40
40
  gem 'w3c_validators', '1.3.7', require: false
41
- gem 'webmock', '3.24.0', require: false
41
+ gem 'webmock', '3.25.0', require: false
42
42
  gem 'yard', '0.9.37', require: false
data/Gemfile.lock CHANGED
@@ -179,7 +179,7 @@ GEM
179
179
  reline (0.6.0)
180
180
  io-console (~> 0.5)
181
181
  rexml (3.4.0)
182
- rspec-core (3.13.2)
182
+ rspec-core (3.13.3)
183
183
  rspec-support (~> 3.13.0)
184
184
  rspec-expectations (3.13.3)
185
185
  diff-lcs (>= 1.2.0, < 2.0)
@@ -187,7 +187,7 @@ GEM
187
187
  rspec-mocks (3.13.2)
188
188
  diff-lcs (>= 1.2.0, < 2.0)
189
189
  rspec-support (~> 3.13.0)
190
- rspec-rails (7.1.0)
190
+ rspec-rails (7.1.1)
191
191
  actionpack (>= 7.0)
192
192
  activesupport (>= 7.0)
193
193
  railties (>= 7.0)
@@ -245,7 +245,7 @@ GEM
245
245
  json (>= 1.8)
246
246
  nokogiri (~> 1.6)
247
247
  rexml (~> 3.2)
248
- webmock (3.24.0)
248
+ webmock (3.25.0)
249
249
  addressable (>= 2.8.0)
250
250
  crack (>= 0.3.2)
251
251
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -270,7 +270,7 @@ DEPENDENCIES
270
270
  qbash!
271
271
  rake (= 13.2.1)
272
272
  random-port (~> 0.0)
273
- rspec-rails (= 7.1.0)
273
+ rspec-rails (= 7.1.1)
274
274
  rubocop (= 1.71.2)
275
275
  rubocop-minitest (= 0.36.0)
276
276
  rubocop-performance (= 1.23.1)
@@ -279,7 +279,7 @@ DEPENDENCIES
279
279
  simplecov (= 0.22.0)
280
280
  simplecov-cobertura (= 2.1.0)
281
281
  w3c_validators (= 1.3.7)
282
- webmock (= 3.24.0)
282
+ webmock (= 3.25.0)
283
283
  yard (= 0.9.37)
284
284
 
285
285
  BUNDLED WITH
data/README.md CHANGED
@@ -74,6 +74,16 @@ qbash(
74
74
  )
75
75
  ```
76
76
 
77
+ If a block is given to `qbash`, it will run the command in background mode,
78
+ waiting for the block to finish. Once it's finished, the command will be
79
+ terminated via the `TERM` [signal]:
80
+
81
+ ```ruby
82
+ qbash('sleep 9999') do |pid|
83
+ # do something
84
+ end
85
+ ```
86
+
77
87
  It is very much recommended to escape all command-line values with the help
78
88
  of the [Shellwords.escape()][shellwords] utility method, for example:
79
89
 
@@ -86,7 +96,7 @@ Without such an escaping, in this example, a space inside the `file`
86
96
  will lead to an unpredicatable result of the execution.
87
97
 
88
98
  If you want to stop sooner than the command finishes, use
89
- [`timeout`](https://github.com/ruby/timeout) gem:
99
+ [timeout] gem:
90
100
 
91
101
  ```ruby
92
102
  require 'timeout'
@@ -116,3 +126,5 @@ If it's clean and you don't see any error messages, submit your pull request.
116
126
 
117
127
  [shellwords]: https://ruby-doc.org/stdlib-3.0.1/libdoc/shellwords/rdoc/Shellwords.html
118
128
  [qbash]: https://rubydoc.info/github/yegor256/qbash/master/Kernel#qbash-instance_method
129
+ [signal]: https://en.wikipedia.org/wiki/Signal_(IPC)
130
+ [timeout]: https://github.com/ruby/timeout
data/lib/qbash.rb CHANGED
@@ -89,25 +89,35 @@ module Kernel
89
89
  sin.write(stdin)
90
90
  sin.close
91
91
  if block_given?
92
- Thread.new do
93
- until sout.closed?
94
- begin
95
- ln = sout.gets
96
- rescue IOError => e
97
- ln = Backtrace.new(e).to_s
92
+ closed = false
93
+ watch =
94
+ Thread.new do
95
+ until closed
96
+ begin
97
+ ln = sout.gets
98
+ rescue IOError => e
99
+ ln = Backtrace.new(e).to_s
100
+ end
101
+ ln = "##{thr.pid}: #{ln}"
102
+ if log.nil?
103
+ # no logging
104
+ elsif log.respond_to?(mtd)
105
+ log.__send__(mtd, ln)
106
+ else
107
+ log.print(ln)
108
+ end
109
+ buf += ln
98
110
  end
99
- ln = "##{thr.pid}: #{ln}"
100
- if log.nil?
101
- # no logging
102
- elsif log.respond_to?(mtd)
103
- log.__send__(mtd, ln)
104
- else
105
- log.print(ln)
106
- end
107
- buf += ln
108
111
  end
112
+ pid = thr.pid
113
+ yield pid
114
+ begin
115
+ Process.kill('TERM', pid)
116
+ rescue Errno::ESRCH
117
+ # simply ignore it
109
118
  end
110
- yield thr.pid
119
+ closed = true
120
+ watch.join
111
121
  else
112
122
  until sout.eof?
113
123
  begin
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.3.2'
29
+ s.version = '0.4.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Quick Executor of a BASH Command'
32
32
  s.description =
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-04 00:00:00.000000000 Z
11
+ date: 2025-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace