process_helper 0.1.1 → 0.1.2.pre.beta.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.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/process_helper.rb +6 -2
- data/process_helper.gemspec +1 -1
- data/spec/output_handling_spec.rb +9 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe565a56a28dd005bbd6772a14e1ca917d521d4
|
4
|
+
data.tar.gz: a97b43fc84e8c3cbe778d626c4a5f2f09aaa81af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47bbcfde26d525ed4b592eb006135cf0296916e488761efa0cee05a03763ae4c6ff3720a230a570d233e0b5e0a3bc2c3616e023b75511a0f85d3e3848dfb6cbc
|
7
|
+
data.tar.gz: 06cd7b2e798b29824ce23bdfa6b7e9fbb41800db1c0ab7fe4e7c4ecbe5bd3b4a64dcf297a5adcf43534d3f642e559aea64cd94de28a3d805bc29ffab788585ca
|
data/README.md
CHANGED
@@ -51,6 +51,7 @@ However, `process_helper` was created because none of them made it *easy* to run
|
|
51
51
|
* [`:timeout` (short form `:kill`)](#timeout-short-form-kill)
|
52
52
|
* [`:log_cmd` (short form `:log`)](#log_cmd-short-form-log)
|
53
53
|
* [Warnings if failure output will be suppressed based on options](#warnings-if-failure-output-will-be-suppressed-based-on-options)
|
54
|
+
* [Example Helper Script](#example-helper-script)
|
54
55
|
* [Version](#version)
|
55
56
|
* [Contributing](#contributing)
|
56
57
|
* [(Un)License](#unlicense)
|
@@ -248,6 +249,31 @@ WARNING: Check your ProcessHelper options - :puts_output is :never, and :include
|
|
248
249
|
=> "ls: /does_not_exist: No such file or directory\n"
|
249
250
|
```
|
250
251
|
|
252
|
+
## Example Helper Script
|
253
|
+
|
254
|
+
You can DRY up your usage of common process helper options by making a helper script like this that you can require:
|
255
|
+
|
256
|
+
`setup_process_helper.rb`
|
257
|
+
```
|
258
|
+
require 'process_helper'
|
259
|
+
include ProcessHelper
|
260
|
+
|
261
|
+
def process_without_output(cmd, options = {})
|
262
|
+
process(cmd, {out: :error, include_output_in_exception: false}.merge(default_options_for_process_helper).merge(options))
|
263
|
+
end
|
264
|
+
|
265
|
+
def process_with_output(cmd, options = {})
|
266
|
+
process(cmd, default_options_for_process_helper.merge(options))
|
267
|
+
end
|
268
|
+
|
269
|
+
def default_options_for_process_helper
|
270
|
+
# IMPORTANT NOTE: Running under a pseudo-terminal (pty) gives coloring and other
|
271
|
+
# benefits, but will result in end-of-line being "\r\n" instead of just "\n".
|
272
|
+
# Be aware of this if attempting to split return value into lines.
|
273
|
+
{log: true, pty: true}
|
274
|
+
end
|
275
|
+
```
|
276
|
+
|
251
277
|
## Version
|
252
278
|
|
253
279
|
You can see the version of ProcessHelper in the `ProcessHelper::VERSION` constant:
|
data/lib/process_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'stringio'
|
|
10
10
|
# Full documentation at https://github.com/thewoolleyman/process_helper
|
11
11
|
module ProcessHelper
|
12
12
|
# Don't forget to keep version in sync with gemspec
|
13
|
-
VERSION = '0.1.1'.freeze
|
13
|
+
VERSION = '0.1.2.pre.beta.1'.freeze
|
14
14
|
|
15
15
|
# rubocop:disable Style/ModuleFunction
|
16
16
|
extend self
|
@@ -98,7 +98,7 @@ module ProcessHelper
|
|
98
98
|
ch = stdout_and_stderr.read_nonblock(1)
|
99
99
|
end
|
100
100
|
break unless ch
|
101
|
-
printf ch if always_puts_output
|
101
|
+
printf format_char(ch) if always_puts_output
|
102
102
|
output += ch
|
103
103
|
stdout_and_stderr.flush
|
104
104
|
end
|
@@ -128,6 +128,10 @@ module ProcessHelper
|
|
128
128
|
output
|
129
129
|
end
|
130
130
|
|
131
|
+
def format_char(ch)
|
132
|
+
ch == '%' ? '%%' : ch
|
133
|
+
end
|
134
|
+
|
131
135
|
def handle_timeout_error(output, options, seconds = nil, additional_msg = nil)
|
132
136
|
msg = "Timed out after #{options.fetch(:timeout, seconds)} seconds."
|
133
137
|
msg += " #{additional_msg}" if additional_msg
|
data/process_helper.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'process_helper'
|
5
5
|
# Don't forget to keep version in sync with ProcessHelper::Version
|
6
|
-
spec.version = '0.1.1'
|
6
|
+
spec.version = '0.1.2.pre.beta.1'
|
7
7
|
spec.authors = ['Chad Woolley', 'Glenn Oppegard']
|
8
8
|
spec.email = ['oppegard@gmail.com', 'thewoolleyman@gmail.com']
|
9
9
|
spec.summary = "Makes it easier to spawn ruby sub-processes with proper capturing /
|
@@ -34,6 +34,15 @@ RSpec.describe 'output handling' do
|
|
34
34
|
.and(not_output.to_stderr)
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'escapes non-format % characters' do
|
38
|
+
expect do
|
39
|
+
clazz.process(
|
40
|
+
'echo %',
|
41
|
+
puts_output: :always)
|
42
|
+
end.to output("%\n").to_stdout
|
43
|
+
.and(not_output.to_stderr)
|
44
|
+
end
|
45
|
+
|
37
46
|
describe 'when :puts_output == :never' do
|
38
47
|
describe 'when include_output_in_exception is false' do
|
39
48
|
it 'show warning' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
4
|
+
version: 0.1.2.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Woolley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -185,12 +185,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: 1.9.2
|
186
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
187
|
requirements:
|
188
|
-
- - "
|
188
|
+
- - ">"
|
189
189
|
- !ruby/object:Gem::Version
|
190
|
-
version:
|
190
|
+
version: 1.3.1
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.
|
193
|
+
rubygems_version: 2.5.2
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: Makes it easier to spawn ruby sub-processes with proper capturing / of stdout
|