qbash 0.7.2 → 0.8.1

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +16 -14
  3. data/README.md +7 -0
  4. data/lib/qbash.rb +26 -5
  5. data/qbash.gemspec +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c3c40cb0bdd68143a0b22ded870db02285d3ccb8b1d43601b10f739b5d010b3
4
- data.tar.gz: d7737d980e9bd519b365d5d86a53fa1193c40f7f06957c37e034488dc45bb1bb
3
+ metadata.gz: d8c4b0ec8a522c9c681643d578bada1d65edc2dd561b6b121b14ab1a06e29688
4
+ data.tar.gz: e5a640af08de6d772bfdaf3e61e18e125ea9a816bcd2983bededab7c79ce5f1e
5
5
  SHA512:
6
- metadata.gz: d800d78d8b9316355dbdda2c949f05f59e8e4ed0d562e4b463eab7eee74ae9d45cf68928ca1f83188720aac3f5dc9ef195410c0978fae50a6e7401ae02464ebb
7
- data.tar.gz: 59e51dcfd7263ef01656520cf49319a64b4680944ab770e6f3f92a8feca7c4f29e02ef19fac7821cdf89cc0856345750465284ea04d97bda91db87c228b4948a
6
+ metadata.gz: 239d00385031c4e778db41478e4ad58f00c963c4850a038f5fa716c3da983aad4e6bdb5ed458080ec76b329472f4240fe5e47abe31cf4429d2ee0fde1cc5886d
7
+ data.tar.gz: d6d49dffd4aeab9ee32413d79fa0ffeb19aaa1b51db389e665a5e4a0c97aaa261e44786ba8aee59c26c9707d478ed6f9e0a391a920982feb48b55a146b8c8754
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.8.8)
13
+ addressable (2.8.9)
14
14
  public_suffix (>= 2.0.2, < 8.0)
15
15
  ansi (1.5.0)
16
16
  ast (2.4.3)
@@ -34,7 +34,7 @@ GEM
34
34
  multi_test (~> 1.1)
35
35
  sys-uname (~> 1.3)
36
36
  cucumber-ci-environment (11.0.0)
37
- cucumber-core (16.1.1)
37
+ cucumber-core (16.2.0)
38
38
  cucumber-gherkin (> 36, < 40)
39
39
  cucumber-messages (> 31, < 33)
40
40
  cucumber-tag-expressions (> 6, < 9)
@@ -49,7 +49,8 @@ GEM
49
49
  date (3.5.1)
50
50
  diff-lcs (1.6.2)
51
51
  docile (1.4.1)
52
- elapsed (0.2.2)
52
+ drb (2.2.3)
53
+ elapsed (0.3.1)
53
54
  loog (~> 0.6)
54
55
  tago (~> 0.1)
55
56
  ellipsized (0.3.0)
@@ -62,17 +63,18 @@ GEM
62
63
  ffi (1.17.3-x86_64-darwin)
63
64
  ffi (1.17.3-x86_64-linux-gnu)
64
65
  hashdiff (1.2.1)
65
- json (2.18.0)
66
+ json (2.19.3)
66
67
  language_server-protocol (3.17.0.5)
67
68
  lint_roller (1.1.0)
68
69
  logger (1.7.0)
69
- loog (0.7.2)
70
+ loog (0.8.0)
70
71
  ellipsized
71
72
  logger (~> 1.0)
72
73
  memoist3 (1.0.0)
73
74
  mini_mime (1.1.5)
74
75
  mini_portile2 (2.8.9)
75
- minitest (6.0.1)
76
+ minitest (6.0.3)
77
+ drb (~> 2.0)
76
78
  prism (~> 1.5)
77
79
  minitest-reporters (1.7.1)
78
80
  ansi
@@ -97,26 +99,26 @@ GEM
97
99
  nokogiri (1.19.0-x86_64-linux-gnu)
98
100
  racc (~> 1.4)
99
101
  parallel (1.27.0)
100
- parser (3.3.10.1)
102
+ parser (3.3.11.1)
101
103
  ast (~> 2.4.1)
102
104
  racc
103
105
  prism (1.9.0)
104
106
  psych (5.3.1)
105
107
  date
106
108
  stringio
107
- public_suffix (7.0.2)
109
+ public_suffix (7.0.5)
108
110
  racc (1.8.1)
109
111
  rainbow (3.1.1)
110
112
  rake (13.3.1)
111
- random-port (0.7.6)
113
+ random-port (0.8.2)
112
114
  tago (~> 0.0)
113
- rdoc (7.1.0)
115
+ rdoc (7.2.0)
114
116
  erb
115
117
  psych (>= 4.0.0)
116
118
  tsort
117
119
  regexp_parser (2.11.3)
118
120
  rexml (3.4.4)
119
- rubocop (1.84.0)
121
+ rubocop (1.86.0)
120
122
  json (~> 2.3)
121
123
  language_server-protocol (~> 3.17.0.2)
122
124
  lint_roller (~> 1.1.0)
@@ -127,10 +129,10 @@ GEM
127
129
  rubocop-ast (>= 1.49.0, < 2.0)
128
130
  ruby-progressbar (~> 1.7)
129
131
  unicode-display_width (>= 2.4.0, < 4.0)
130
- rubocop-ast (1.49.0)
132
+ rubocop-ast (1.49.1)
131
133
  parser (>= 3.3.7.2)
132
134
  prism (~> 1.7)
133
- rubocop-minitest (0.38.2)
135
+ rubocop-minitest (0.39.1)
134
136
  lint_roller (~> 1.1)
135
137
  rubocop (>= 1.75.0, < 2.0)
136
138
  rubocop-ast (>= 1.38.0, < 2.0)
@@ -164,7 +166,7 @@ GEM
164
166
  json (>= 1.8)
165
167
  nokogiri (~> 1.6)
166
168
  rexml (~> 3.2)
167
- webmock (3.26.1)
169
+ webmock (3.26.2)
168
170
  addressable (>= 2.8.0)
169
171
  crack (>= 0.3.2)
170
172
  hashdiff (>= 0.4.0, < 2.0.0)
data/README.md CHANGED
@@ -128,6 +128,13 @@ end
128
128
  This raises a `Timeout::Error` exception after five seconds
129
129
  of waiting for `sleep` to finish.
130
130
 
131
+ By default, `qbash` runs commands through `/bin/bash`.
132
+ To run commands through the system shell instead (useful on Windows), use:
133
+
134
+ ```ruby
135
+ qbash('dir C:\\', raw: true)
136
+ ```
137
+
131
138
  ## How to contribute
132
139
 
133
140
  Read [these guidelines][guidelines].
data/lib/qbash.rb CHANGED
@@ -75,6 +75,12 @@ module Kernel
75
75
  # # Useful for commands that operate on the current directory
76
76
  # qbash('git status', chdir: '/path/to/repo')
77
77
  #
78
+ # == Raw Mode (System Shell)
79
+ #
80
+ # # Run command through the system shell instead of /bin/bash
81
+ # # Useful on Windows where /bin/bash is not available
82
+ # qbash('dir C:\\', raw: true)
83
+ #
78
84
  # For command with multiple arguments, you can use +Shellwords.escape()+ to
79
85
  # properly escape each argument.
80
86
  #
@@ -104,9 +110,10 @@ module Kernel
104
110
  # @param [Boolean] both If set to TRUE, the function returns an array +(stdout, code)+
105
111
  # @param [Integer] level Logging level (use +Logger::DEBUG+, +Logger::INFO+, +Logger::WARN+, or +Logger::ERROR+)
106
112
  # @param [String] chdir Directory to change to before running the command (or +nil+ to use current directory)
113
+ # @param [Boolean] raw If +true+, run the command via the system shell instead of +/bin/bash+
107
114
  # @return [String] Everything that was printed to the +stdout+ by the command
108
115
  def qbash(*cmd, opts: [], stdin: '', env: {}, stdout: Loog::NULL, stderr: nil, accept: [0], both: false,
109
- level: Logger::DEBUG, chdir: nil)
116
+ level: Logger::DEBUG, chdir: nil, raw: false)
110
117
  stderr ||= stdout
111
118
  env.each { |k, v| raise "env[#{k}] is nil" if v.nil? }
112
119
  env = env.transform_values(&:to_s)
@@ -138,8 +145,13 @@ module Kernel
138
145
  buf = +''
139
146
  e = 1
140
147
  start = Time.now
141
- bash = ['/bin/bash'] + opts + ['-c', cmd]
142
- popen = chdir.nil? ? [env, *bash] : [env, *bash, { chdir: }]
148
+ popen =
149
+ if raw
150
+ chdir.nil? ? [env, cmd] : [env, cmd, { chdir: }]
151
+ else
152
+ bash = ['/bin/bash'] + opts + ['-c', cmd]
153
+ chdir.nil? ? [env, *bash] : [env, *bash, { chdir: }]
154
+ end
143
155
  Open3.send(:popen3, *popen) do |sin, sout, serr, ctrl|
144
156
  pid = ctrl.pid
145
157
  printer[stderr, "+ #{cmd} /##{pid}"]
@@ -189,8 +201,17 @@ module Kernel
189
201
  else
190
202
  thread = Thread.new { consume.call(serr, stderr, nil) }
191
203
  thread.abort_on_exception = true
192
- consume.call(sout, stdout, buf)
193
- thread.join
204
+ begin
205
+ consume.call(sout, stdout, buf)
206
+ thread.join
207
+ rescue SignalException => e
208
+ begin
209
+ Process.kill(e.signo, pid)
210
+ rescue StandardError
211
+ nil
212
+ end
213
+ raise
214
+ end
194
215
  end
195
216
  e = ctrl.value.exitstatus
196
217
  if !accept.nil? && !accept.include?(e)
data/qbash.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.required_ruby_version = '>=3.2'
11
11
  s.name = 'qbash'
12
- s.version = '0.7.2'
12
+ s.version = '0.8.1'
13
13
  s.license = 'MIT'
14
14
  s.summary = 'Quick Executor of a BASH Command'
15
15
  s.description =
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.7.2
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko