qbash 0.1.0 → 0.2.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: 010ab8ee65105e6dd7d463e0f86a93ab0816c85d390de47c0e146fdf3d101cb4
4
- data.tar.gz: 1fa31fc03e965c1a41c435b0722443ef4836455febe350e7a129402965a1df69
3
+ metadata.gz: 39244de3b00f6094ec91699c5a7eb8f0e2e7cf53670233dfb21d5df3a05d00fc
4
+ data.tar.gz: 8f17ae0148d5a5426ca7754bc12f1746b57b0f9c82fd4a48f0611dee186dc760
5
5
  SHA512:
6
- metadata.gz: 19933d40b4ac18a7d9db6d9328fd09d303971aa113bbff8a4c655db4cdbed14b682e95487134e33cb5e443dcf826996ffc8d39065cecfc6c1dd1bb57147abf47
7
- data.tar.gz: 33a7904018b3b781a1efdebf39cb6fdfc96e6ec578803948a1b446b116ccc4e53630939ad63e3de2ba0c38f8cae4695f1e1f9b665196720dc5ed0b6473179a48
6
+ metadata.gz: 4ea302ab3a7094e337b55367c8c10db61465d7ac24187e2691346f25ca1db4ec587c4f6a72b3c9d9c148f9347beabcb6a6f8fb16cd07e09ffd5b12af6521fd3a
7
+ data.tar.gz: 3c56561a93b211904ac4482df6cf1f3dd31b989792f984e691259d7374f7a51bdf091354149324ddb3460efc7769c3f6db4f489e413d59af7e20d7ae916049d7
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,10 +53,9 @@ 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
60
  cmd = cmd.reject { |a| a.nil? || a.empty? }.join(' ') if cmd.is_a?(Array)
62
61
  mtd =
@@ -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.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
@@ -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.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-20 00:00:00.000000000 Z
11
+ date: 2024-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace