qbash 0.2.1 → 0.2.3

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: 39338c15ddd4926d63fda7043f8f1037e0b6c6d6796e2e40a40e5d184963fdd1
4
- data.tar.gz: 1198126dc03e798b35ba5a22499e48efdbd29fe477c9386b694687c0be1d60ed
3
+ metadata.gz: a765a1decf65f3211a89fb0d0f64faa5a731f463b90e6e2bf7a4b3399b02f2bb
4
+ data.tar.gz: ad56a45ee01b3397b2c1f45674ec7147c804454de8566da50751f5eece1937f1
5
5
  SHA512:
6
- metadata.gz: 2c91c96828249e4f4116e322fc08b07fb75acef2d2c6a1e102cf9440c0e5f12a91d609ddb69969f7cf079293cb7d1b56242853f049935dc895f5e4536693e80d
7
- data.tar.gz: 32ae547117a5ee567dc4cd488b9c54264975c6705d56798654e06bf8d150a7da52b5a30e94d508d986252784890abdcc81de36a80238bf3d85835aee5f786bd9
6
+ metadata.gz: 05e3085e88e721c09b3a8613f719a4634b7a77c6837b4a18354e6b1eae2620ac0779c5eab650569e68c533fe73c6dd558b8617b6161578feb63b7e22c65a1929
7
+ data.tar.gz: b9c956477af17a1ea4cce829ef162132059c05336d89bd84863eff354db903a02331399ab15f8fb95b514638605cc5162ad91c1fcebff372d10796cceaa26e92
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
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.
@@ -50,7 +50,7 @@ module Kernel
50
50
  # @param [String] cmd The command to run, for example +echo "Hello, world!"+
51
51
  # @param [String] stdin The +stdin+ to provide to the command
52
52
  # @param [Hash] env Hash of environment variables
53
- # @param [Loog|IO] log Logging facility with +.debug()+ method (or +$stdout+)
53
+ # @param [Loog|IO] log Logging facility with +.debug()+ method (or +$stdout+, or nil if should go to +/dev/null+)
54
54
  # @param [Array] accept List of accepted exit codes (accepts all if the list is +nil+)
55
55
  # @param [Boolean] both If set to TRUE, the function returns an array +(stdout, code)+
56
56
  # @param [Integer] level Logging level (use +Logger::DEBUG+, +Logger::INFO+, +Logger::WARN+, or +Logger::ERROR+)
@@ -71,7 +71,9 @@ module Kernel
71
71
  else
72
72
  raise "Unknown log level #{level}"
73
73
  end
74
- if log.respond_to?(mtd)
74
+ if log.nil?
75
+ # nothing to print
76
+ elsif log.respond_to?(mtd)
75
77
  log.__send__(mtd, "+ #{cmd}")
76
78
  else
77
79
  log.print("+ #{cmd}\n")
@@ -79,31 +81,29 @@ module Kernel
79
81
  buf = ''
80
82
  e = 1
81
83
  start = Time.now
82
- thread =
83
- Thread.new do
84
- Open3.popen2e(env, "/bin/bash -c #{Shellwords.escape(cmd)}") do |sin, sout, thr|
85
- sin.write(stdin)
86
- sin.close
87
- until sout.eof?
88
- begin
89
- ln = sout.gets
90
- rescue IOError => e
91
- ln = Backtrace.new(e).to_s
92
- end
93
- if log.respond_to?(mtd)
94
- log.__send__(mtd, ln)
95
- else
96
- log.print("#{ln}\n")
97
- end
98
- buf += ln
99
- end
100
- e = thr.value.to_i
101
- if !accept.nil? && !accept.include?(e)
102
- raise "The command '#{cmd}' failed with exit code ##{e} in #{start.ago}\n#{buf}"
103
- end
84
+ Open3.popen2e(env, "/bin/bash -c #{Shellwords.escape(cmd)}") do |sin, sout, thr|
85
+ sin.write(stdin)
86
+ sin.close
87
+ until sout.eof?
88
+ begin
89
+ ln = sout.gets
90
+ rescue IOError => e
91
+ ln = Backtrace.new(e).to_s
104
92
  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")
99
+ 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
105
  end
106
- thread.join
106
+ end
107
107
  return [buf, e] if both
108
108
  buf
109
109
  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.1'
29
+ s.version = '0.2.3'
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
@@ -59,6 +59,10 @@ class TestQbash < Minitest::Test
59
59
  assert_equal('Hi!', qbash(['printf', nil, 'Hi!', '']))
60
60
  end
61
61
 
62
+ def test_log_to_nil
63
+ assert_equal("yes\n", qbash('echo yes', log: nil))
64
+ end
65
+
62
66
  def test_accept_zero
63
67
  qbash('echo hi', accept: nil)
64
68
  end
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.1
4
+ version: 0.2.3
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