qbash 0.1.0 → 0.2.1

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: 010ab8ee65105e6dd7d463e0f86a93ab0816c85d390de47c0e146fdf3d101cb4
4
- data.tar.gz: 1fa31fc03e965c1a41c435b0722443ef4836455febe350e7a129402965a1df69
3
+ metadata.gz: 39338c15ddd4926d63fda7043f8f1037e0b6c6d6796e2e40a40e5d184963fdd1
4
+ data.tar.gz: 1198126dc03e798b35ba5a22499e48efdbd29fe477c9386b694687c0be1d60ed
5
5
  SHA512:
6
- metadata.gz: 19933d40b4ac18a7d9db6d9328fd09d303971aa113bbff8a4c655db4cdbed14b682e95487134e33cb5e443dcf826996ffc8d39065cecfc6c1dd1bb57147abf47
7
- data.tar.gz: 33a7904018b3b781a1efdebf39cb6fdfc96e6ec578803948a1b446b116ccc4e53630939ad63e3de2ba0c38f8cae4695f1e1f9b665196720dc5ed0b6473179a48
6
+ metadata.gz: 2c91c96828249e4f4116e322fc08b07fb75acef2d2c6a1e102cf9440c0e5f12a91d609ddb69969f7cf079293cb7d1b56242853f049935dc895f5e4536693e80d
7
+ data.tar.gz: 32ae547117a5ee567dc4cd488b9c54264975c6705d56798654e06bf8d150a7da52b5a30e94d508d986252784890abdcc81de36a80238bf3d85835aee5f786bd9
data/README.md CHANGED
@@ -85,13 +85,18 @@ qbash("cat #{Shellwords.escape(file)}")
85
85
  Without such an escaping, in this example, a space inside the `file`
86
86
  will lead to an unpredicatable result of the execution.
87
87
 
88
- You can also set the maximum time for the command:
88
+ If you want to stop sooner than the command finishes, use
89
+ [`timeout`](https://github.com/ruby/timeout) gem:
89
90
 
90
91
  ```ruby
91
- qbash("sleep 100", timeout: 4)
92
+ require 'timeout'
93
+ Timeout.timeout(5) do
94
+ qbash('sleep 100')
95
+ end
92
96
  ```
93
97
 
94
- This command will raise exception after four seconds.
98
+ This command will raise `Timeout::Error` exception after five seconds
99
+ of waiting for the `sleep` to finish.
95
100
 
96
101
  ## How to contribute
97
102
 
data/lib/qbash.rb CHANGED
@@ -53,12 +53,11 @@ module Kernel
53
53
  # @param [Loog|IO] log Logging facility with +.debug()+ method (or +$stdout+)
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
- # @param [Integer] timeout If it's set to non-NIL, the execution will fail after this number of seconds
57
56
  # @param [Integer] level Logging level (use +Logger::DEBUG+, +Logger::INFO+, +Logger::WARN+, or +Logger::ERROR+)
58
57
  # @return [String] Everything that was printed to the +stdout+ by the command
59
- def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, timeout: nil, level: Logger::DEBUG)
58
+ def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, level: Logger::DEBUG)
60
59
  env.each { |k, v| raise "env[#{k}] is nil" if v.nil? }
61
- cmd = cmd.reject { |a| a.nil? || a.empty? }.join(' ') if cmd.is_a?(Array)
60
+ cmd = cmd.reject { |a| a.nil? || (a.is_a?(String) && a.empty?) }.join(' ') if cmd.is_a?(Array)
62
61
  mtd =
63
62
  case level
64
63
  when Logger::DEBUG
@@ -104,7 +103,7 @@ module Kernel
104
103
  end
105
104
  end
106
105
  end
107
- raise "Execution of #{cmd} timed out in #{start.ago}" if thread.join(timeout).nil?
106
+ thread.join
108
107
  return [buf, e] if both
109
108
  buf
110
109
  end
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.1.0'
29
+ s.version = '0.2.1'
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
@@ -42,7 +42,7 @@ class TestQbash < Minitest::Test
42
42
  end
43
43
 
44
44
  def test_command_as_array
45
- assert_equal('123', qbash(['printf 1;', 'printf 2;', 'printf 3']))
45
+ assert_equal('123', qbash(['printf 1;', 'printf 2;', 'printf', 3]))
46
46
  end
47
47
 
48
48
  def test_log_to_console
@@ -72,12 +72,6 @@ class TestQbash < Minitest::Test
72
72
  end
73
73
  end
74
74
 
75
- def test_with_timeout
76
- assert_raises do
77
- qbash('sleep 100', timeout: 0.1)
78
- end
79
- end
80
-
81
75
  def test_with_special_symbols
82
76
  assert_equal("'hi'\n", qbash("echo \"'hi'\""))
83
77
  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.1.0
4
+ version: 0.2.1
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-20 00:00:00.000000000 Z
11
+ date: 2024-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace