qbash 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83183014aa9cde18aa4c0924665c2f1d18940d4f4ff64a66602a0ba973aa1aa0
4
- data.tar.gz: 69881b928dbf2526c9e89542620d27d1cc90ffde48dd369ed2dfbe4051c0e724
3
+ metadata.gz: 9db87ce0fe83225ddc40e2b699957b8f1d3dd9a736865e5a43f4d1cdcd37d429
4
+ data.tar.gz: 0c9b65c4f1be9e553b572b8e75a6d3954b69e90af91adde800802c04978b2bb1
5
5
  SHA512:
6
- metadata.gz: c4800029b521eb3372ca256ccb874b816207d589753977ede31afb293b9922e7ab477057fdeaca94aa435e0e8ecb47a677fd2e6be39c14a7aacbd0f14aad1d07
7
- data.tar.gz: 0d87c04e4f0e2d85b1208da0824161d6c720a39268e1e3838791d2776b41a331c0f6086429d680ddf1c46429db4b2fb3e211aeac50ef175c9804057a491b6db9
6
+ metadata.gz: d7be9b834c66b171c4dc56b843b51de47213e1e13c14106dd456800eae8a017ec08dc78b78c0ad9d9ff910bcfc6fba3e7883ecd1808e6736b6e0e89d6ae6a8b8
7
+ data.tar.gz: d3165d8d72eb52b2f13668da36f74cbf5ac55cf59db60682dd2f1434c21eeede46e509c053cd7862192b258e6b890c995bf87b2fd17ba3398d58e5085c7e99f1
data/.0pdd.yml CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/.rultor.yml CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2024 Yegor Bugayenko
1
+ # Copyright (c) 2024-2025 Yegor Bugayenko
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the 'Software'), to deal
data/.simplecov CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2024 Yegor Bugayenko
4
+ # Copyright (c) 2024-2025 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -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/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -31,7 +31,7 @@ gem 'rake', '13.2.1', require: false
31
31
  gem 'random-port', '~>0.0', require: false
32
32
  gem 'rspec-rails', '7.1.0', require: false
33
33
  gem 'rubocop', '1.69.2', require: false
34
- gem 'rubocop-performance', '1.23.0', require: false
34
+ gem 'rubocop-performance', '1.23.1', require: false
35
35
  gem 'rubocop-rspec', '3.3.0', require: false
36
36
  gem 'simplecov', '0.22.0', require: false
37
37
  gem 'simplecov-cobertura', '2.1.0', require: false
data/Gemfile.lock CHANGED
@@ -100,7 +100,7 @@ GEM
100
100
  irb (1.14.1)
101
101
  rdoc (>= 4.0.0)
102
102
  reline (>= 0.4.2)
103
- json (2.9.0)
103
+ json (2.9.1)
104
104
  language_server-protocol (3.17.0.3)
105
105
  logger (1.6.1)
106
106
  loofah (2.23.1)
@@ -162,7 +162,8 @@ GEM
162
162
  zeitwerk (~> 2.6)
163
163
  rainbow (3.1.1)
164
164
  rake (13.2.1)
165
- random-port (0.7.1)
165
+ random-port (0.7.4)
166
+ tago (> 0)
166
167
  rdoc (6.7.0)
167
168
  psych (>= 4.0.0)
168
169
  regexp_parser (2.9.3)
@@ -198,7 +199,7 @@ GEM
198
199
  unicode-display_width (>= 2.4.0, < 4.0)
199
200
  rubocop-ast (1.36.2)
200
201
  parser (>= 3.3.1.0)
201
- rubocop-performance (1.23.0)
202
+ rubocop-performance (1.23.1)
202
203
  rubocop (>= 1.48.1, < 2.0)
203
204
  rubocop-ast (>= 1.31.1, < 2.0)
204
205
  rubocop-rspec (3.3.0)
@@ -253,7 +254,7 @@ DEPENDENCIES
253
254
  random-port (~> 0.0)
254
255
  rspec-rails (= 7.1.0)
255
256
  rubocop (= 1.69.2)
256
- rubocop-performance (= 1.23.0)
257
+ rubocop-performance (= 1.23.1)
257
258
  rubocop-rspec (= 3.3.0)
258
259
  simplecov (= 0.22.0)
259
260
  simplecov-cobertura (= 2.1.0)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/qbash.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -30,7 +30,7 @@ require 'tago'
30
30
  # Execute one bash command.
31
31
  #
32
32
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
34
34
  # License:: MIT
35
35
  module Kernel
36
36
  # Execute a single bash command.
@@ -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!"+
@@ -81,33 +85,33 @@ module Kernel
81
85
  buf = ''
82
86
  e = 1
83
87
  start = Time.now
84
- thread =
85
- Thread.new do
86
- Open3.popen2e(env, "/bin/bash -c #{Shellwords.escape(cmd)}") do |sin, sout, thr|
87
- sin.write(stdin)
88
- sin.close
89
- until sout.eof?
90
- begin
91
- ln = sout.gets
92
- rescue IOError => e
93
- ln = Backtrace.new(e).to_s
94
- end
95
- if log.nil?
96
- # no logging
97
- elsif log.respond_to?(mtd)
98
- log.__send__(mtd, ln)
99
- else
100
- log.print("#{ln}\n")
101
- end
102
- buf += ln
88
+ Open3.popen2e(env, "/bin/bash -c #{Shellwords.escape(cmd)}") do |sin, sout, thr|
89
+ sin.write(stdin)
90
+ sin.close
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
103
99
  end
104
- e = thr.value.to_i
105
- if !accept.nil? && !accept.include?(e)
106
- raise "The command '#{cmd}' failed with exit code ##{e} in #{start.ago}\n#{buf}"
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")
107
106
  end
107
+ buf += ln
108
+ end
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}"
108
112
  end
109
113
  end
110
- thread.join
114
+ end
111
115
  return [buf, e] if both
112
116
  buf
113
117
  end
data/qbash.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -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.2'
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__helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/test/test_qbash.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
3
+ # Copyright (c) 2024-2025 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -30,7 +30,7 @@ require_relative '../lib/qbash'
30
30
 
31
31
  # Test.
32
32
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
34
34
  # License:: MIT
35
35
  class TestQbash < Minitest::Test
36
36
  def test_basic_run
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.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: 2024-12-26 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace