qbash 0.2.0 → 0.2.2
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 +4 -4
- data/lib/qbash.rb +8 -4
- data/qbash.gemspec +1 -1
- data/test/test_qbash.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83183014aa9cde18aa4c0924665c2f1d18940d4f4ff64a66602a0ba973aa1aa0
|
4
|
+
data.tar.gz: 69881b928dbf2526c9e89542620d27d1cc90ffde48dd369ed2dfbe4051c0e724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4800029b521eb3372ca256ccb874b816207d589753977ede31afb293b9922e7ab477057fdeaca94aa435e0e8ecb47a677fd2e6be39c14a7aacbd0f14aad1d07
|
7
|
+
data.tar.gz: 0d87c04e4f0e2d85b1208da0824161d6c720a39268e1e3838791d2776b41a331c0f6086429d680ddf1c46429db4b2fb3e211aeac50ef175c9804057a491b6db9
|
data/lib/qbash.rb
CHANGED
@@ -50,14 +50,14 @@ 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+)
|
57
57
|
# @return [String] Everything that was printed to the +stdout+ by the command
|
58
58
|
def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, level: Logger::DEBUG)
|
59
59
|
env.each { |k, v| raise "env[#{k}] is nil" if v.nil? }
|
60
|
-
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)
|
61
61
|
mtd =
|
62
62
|
case level
|
63
63
|
when Logger::DEBUG
|
@@ -71,7 +71,9 @@ module Kernel
|
|
71
71
|
else
|
72
72
|
raise "Unknown log level #{level}"
|
73
73
|
end
|
74
|
-
if log.
|
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")
|
@@ -90,7 +92,9 @@ module Kernel
|
|
90
92
|
rescue IOError => e
|
91
93
|
ln = Backtrace.new(e).to_s
|
92
94
|
end
|
93
|
-
if log.
|
95
|
+
if log.nil?
|
96
|
+
# no logging
|
97
|
+
elsif log.respond_to?(mtd)
|
94
98
|
log.__send__(mtd, ln)
|
95
99
|
else
|
96
100
|
log.print("#{ln}\n")
|
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.2.
|
29
|
+
s.version = '0.2.2'
|
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
|
@@ -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.
|
4
|
+
version: 0.2.2
|
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-
|
11
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|