qbash 0.0.6 → 0.0.8

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: ddc357961a48953ee7c479583b6d648d9ad34873510e7ef6d8096a7bd8e596b5
4
- data.tar.gz: 16dfe814c412365131380e239a93e90532419ece6e66fb3ce0c74bf6566cae5b
3
+ metadata.gz: 34c417c95e1753f5500eb19887e7bb64045a8ed7888232af257a82f84ba71fa7
4
+ data.tar.gz: 4614a0dfd4ce8e692590c80d5ead25a680f49deee23856ee911852f2762baf8a
5
5
  SHA512:
6
- metadata.gz: 15ae921b000efb256d6907b1b69cda9e60a63612d25eccab76b09f0c765d6aa9d1337ed43580b3bf18cfd84a73e69b4f16aaad62065c8df9644a87779c0d8485
7
- data.tar.gz: 6de449a43159e54803266ca16cb960bd09772abbb9a33ad3b5fa77fa25be63cef6e38fa0edb003c342e2c495bfd37b98035365aa76a9a2b9271d99385498ac96
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)
58
- cmd = cmd.join(' ') if cmd.is_a?(Array)
59
- if log.respond_to?(:debug)
60
- log.debug("+ #{cmd}")
59
+ def qbash(cmd, stdin: '', env: {}, log: Loog::NULL, accept: [0], both: false, timeout: nil, level: Logger::DEBUG)
60
+ cmd = cmd.reject { |a| a.nil? || a.empty? }.join(' ') if cmd.is_a?(Array)
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?(:debug)
79
- log.debug(ln)
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.6'
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,6 +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
+
58
+ def test_skip_nil
59
+ assert_equal('Hi!', qbash(['printf', nil, 'Hi!', '']))
60
+ end
61
+
62
+ def test_accept_zero
63
+ qbash('echo hi', accept: nil)
64
+ end
65
+
51
66
  def test_with_stdin
52
67
  Dir.mktmpdir do |home|
53
68
  f = File.join(home, 'a b c.txt')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko