qbash 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/qbash.rb +20 -5
- data/qbash.gemspec +1 -1
- data/test/test_qbash.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34c417c95e1753f5500eb19887e7bb64045a8ed7888232af257a82f84ba71fa7
|
4
|
+
data.tar.gz: 4614a0dfd4ce8e692590c80d5ead25a680f49deee23856ee911852f2762baf8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720d1b9b3ed953125e9a68d308407ede0aa6de2b39c242eb40a31a5e916711c21dd6d57c245536182fff2c72799c7b0f86c6463a6e4d931d21c39d02f68ecf48
|
7
|
+
data.tar.gz: 0f380bf249fea27cd69cfedb460c157b26be03ab3d2c944b21e8a7c09aafc23dbb4500c3bb5f3f6d1262a18bcf2ced2e44f51a0529b5310e2dc337d82109c61f
|
data/lib/qbash.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'backtrace'
|
24
|
+
require 'logger'
|
24
25
|
require 'loog'
|
25
26
|
require 'open3'
|
26
27
|
require 'shellwords'
|
@@ -53,11 +54,25 @@ module Kernel
|
|
53
54
|
# @param [Array] accept List of accepted exit codes (accepts all if the list is +nil+)
|
54
55
|
# @param [Boolean] both If set to TRUE, the function returns an array +(stdout, code)+
|
55
56
|
# @param [Integer] timeout If it's set to non-NIL, the execution will fail after this number of seconds
|
57
|
+
# @param [Integer] level Logging level (use +Logger::DEBUG+, +Logger::INFO+, +Logger::WARN+, or +Logger::ERROR+)
|
56
58
|
# @return [String] Everything that was printed to the +stdout+ by the command
|
57
|
-
def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, timeout: nil)
|
59
|
+
def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, timeout: nil, level: Logger::DEBUG)
|
58
60
|
cmd = cmd.reject { |a| a.nil? || a.empty? }.join(' ') if cmd.is_a?(Array)
|
59
|
-
|
60
|
-
|
61
|
+
mtd =
|
62
|
+
case level
|
63
|
+
when Logger::DEBUG
|
64
|
+
:debug
|
65
|
+
when Logger::INFO
|
66
|
+
:info
|
67
|
+
when Logger::WARN
|
68
|
+
:warn
|
69
|
+
when Logger::ERROR
|
70
|
+
:error
|
71
|
+
else
|
72
|
+
raise "Unknown log level #{level}"
|
73
|
+
end
|
74
|
+
if log.respond_to?(mtd)
|
75
|
+
log.__send__(mtd, "+ #{cmd}")
|
61
76
|
else
|
62
77
|
log.print("+ #{cmd}\n")
|
63
78
|
end
|
@@ -75,8 +90,8 @@ module Kernel
|
|
75
90
|
rescue IOError => e
|
76
91
|
ln = Backtrace.new(e).to_s
|
77
92
|
end
|
78
|
-
if log.respond_to?(
|
79
|
-
log.
|
93
|
+
if log.respond_to?(mtd)
|
94
|
+
log.__send__(mtd, ln)
|
80
95
|
else
|
81
96
|
log.print("#{ln}\n")
|
82
97
|
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.0.
|
29
|
+
s.version = '0.0.8'
|
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
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'minitest/autorun'
|
24
24
|
require 'tmpdir'
|
25
25
|
require 'loog'
|
26
|
+
require 'logger'
|
26
27
|
require 'shellwords'
|
27
28
|
require_relative 'test__helper'
|
28
29
|
require_relative '../lib/qbash'
|
@@ -48,10 +49,20 @@ class TestQbash < Minitest::Test
|
|
48
49
|
qbash('echo Hello world!', log: $stdout)
|
49
50
|
end
|
50
51
|
|
52
|
+
def test_log_to_loog
|
53
|
+
[Logger::DEBUG, Logger::INFO, Logger::WARN, Logger::ERROR].each do |level|
|
54
|
+
qbash('echo Hello world!', log: Loog::NULL, level:)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
51
58
|
def test_skip_nil
|
52
59
|
assert_equal('Hi!', qbash(['printf', nil, 'Hi!', '']))
|
53
60
|
end
|
54
61
|
|
62
|
+
def test_accept_zero
|
63
|
+
qbash('echo hi', accept: nil)
|
64
|
+
end
|
65
|
+
|
55
66
|
def test_with_stdin
|
56
67
|
Dir.mktmpdir do |home|
|
57
68
|
f = File.join(home, 'a b c.txt')
|