process_helper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/{LICENSE → UNLICENSE} +0 -0
- data/lib/process_helper.rb +21 -6
- data/process_helper.gemspec +3 -2
- data/spec/spec_helper.rb +6 -2
- data/spec/version_spec.rb +1 -1
- metadata +17 -8
- data/lib/process_helper/empty_command_error.rb +0 -5
- data/lib/process_helper/invalid_options_error.rb +0 -5
- data/lib/process_helper/unexpected_exit_status_error.rb +0 -5
- data/lib/process_helper/unprocessed_input_error.rb +0 -5
- data/lib/process_helper/version.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29ad0fa584a226473f5a65df1b814c0283958cb
|
4
|
+
data.tar.gz: 3732855e1fe9cb030c64d959555be9a342f3ae84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2960aaf0bc89d84df0a1c580569fb715434e393a8a6e2b352b901fb1f84daf3d9b78fb8b1c9d87955332f32de00bc5ac8c3448dccbb4bcf3b35b9188bf7e3c0a
|
7
|
+
data.tar.gz: 194c492795fa05862416a84eb7a3d5b346f35fa469287b379c488781f68a6bca1557325cf9ac595690a407a463422484ac472623427813d1424acb99f0636f92
|
data/README.md
CHANGED
@@ -45,6 +45,18 @@ And then execute:
|
|
45
45
|
Or install it yourself as:
|
46
46
|
|
47
47
|
$ gem install process_helper
|
48
|
+
|
49
|
+
Or, if you want to avoid a Gem/RubyGems dependency, you can copy the `process_helper.rb` file from the `lib` folder directly into your project and require it:
|
50
|
+
|
51
|
+
# from a ruby file:
|
52
|
+
require_relative 'process_helper'
|
53
|
+
|
54
|
+
# from IRB:
|
55
|
+
require './process_helper'
|
56
|
+
|
57
|
+
# or put the directory containing it on the load path:
|
58
|
+
$LOAD_PATH.unshift('.')
|
59
|
+
require 'process_helper'
|
48
60
|
|
49
61
|
## Usage
|
50
62
|
|
@@ -128,6 +140,27 @@ Valid values are `:always`, `:error`, and `:never`. Default value is `:always`.
|
|
128
140
|
error - i.e. non-zero or unexpected exit status
|
129
141
|
* `:never` will never print output to STDOUT
|
130
142
|
|
143
|
+
### `:timeout` (short form `:kill`)
|
144
|
+
|
145
|
+
***WARNING! This option is beta and will be changed in a future release!***
|
146
|
+
|
147
|
+
Valid value is a float, e.g. `1.5`. Default value is nil/undefined.
|
148
|
+
|
149
|
+
* Currently controls how long `process_helper` will wait to read from
|
150
|
+
a blocked IO stream before timing out (via [IO.select](http://ruby-doc.org/core-2.2.0/IO.html#method-c-select)). For example, invoking `cat` with no arguments, which by default will continue accepting input until killed.
|
151
|
+
* If undefined (default), there will be no timeout, and `process_helper` will hang if a process hangs while waiting to read from IO.
|
152
|
+
|
153
|
+
***The following changes are planned for this option:***
|
154
|
+
|
155
|
+
* Add validation of value (enforced to be a float).
|
156
|
+
* Add ability for the timeout value to also kill long running processes which are ***not*** in blocked waiting on an IO stream read (i.e. kill process regardless of any IO state, not just via [IO.selects](http://ruby-doc.org/core-2.2.0/IO.html#method-c-select) timeout support).
|
157
|
+
* Have both types of timeouts raise different and unique exception classes.
|
158
|
+
* Possibly have different option names to allow different timeout values for the two types of timeouts.
|
159
|
+
|
160
|
+
See [https://www.pivotaltracker.com/story/show/93303096](https://www.pivotaltracker.com/story/show/93303096) for more details.
|
161
|
+
|
162
|
+
|
163
|
+
|
131
164
|
## Warnings if failure output will be suppressed based on options
|
132
165
|
|
133
166
|
ProcessHelper will give you a warning if you pass a combination of options that would
|
@@ -163,6 +196,10 @@ ProcessHelper::VERSION
|
|
163
196
|
you have a single atomic commit on your branch.
|
164
197
|
6. Create a new Pull Request
|
165
198
|
|
199
|
+
## (Un)License
|
200
|
+
|
201
|
+
`process_helper` is (un)licensed under the [unlicense](http://unlicense.org/). So, feel free to copy it into your project (it's usable as a single required file and module), use it, abuse it, do what you will, no attribution required. :)
|
202
|
+
|
166
203
|
## Resources
|
167
204
|
|
168
205
|
Other Ruby Process tools/libraries
|
data/{LICENSE → UNLICENSE}
RENAMED
File without changes
|
data/lib/process_helper.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require_relative 'process_helper/version'
|
2
|
-
require_relative 'process_helper/empty_command_error'
|
3
|
-
require_relative 'process_helper/invalid_options_error'
|
4
|
-
require_relative 'process_helper/unexpected_exit_status_error'
|
5
|
-
require_relative 'process_helper/unprocessed_input_error'
|
6
1
|
require 'open3'
|
7
2
|
|
8
3
|
# Makes it easier to spawn ruby sub-processes with proper capturing of stdout and stderr streams.
|
9
4
|
module ProcessHelper
|
5
|
+
PROCESS_HELPER_VERSION = '0.0.3'
|
6
|
+
|
10
7
|
def process(cmd, options = {})
|
11
8
|
cmd = cmd.to_s
|
12
9
|
fail ProcessHelper::EmptyCommandError, 'command must not be empty' if cmd.empty?
|
@@ -62,7 +59,7 @@ module ProcessHelper
|
|
62
59
|
output_line = nil
|
63
60
|
end
|
64
61
|
rescue EOFError
|
65
|
-
input_lines_processed -= 1
|
62
|
+
input_lines_processed -= 1 if !original_input_lines.empty? && !current_input_line_processed
|
66
63
|
fail_unless_all_input_lines_processed(original_input_lines, input_lines_processed)
|
67
64
|
rescue IO::WaitReadable
|
68
65
|
if input_lines.empty?
|
@@ -255,4 +252,22 @@ module ProcessHelper
|
|
255
252
|
options[:expected_exit_status] =
|
256
253
|
[options[:expected_exit_status]]
|
257
254
|
end
|
255
|
+
|
256
|
+
# Custom Exception Classes:
|
257
|
+
|
258
|
+
# Error which is raised when a command is empty
|
259
|
+
class EmptyCommandError < RuntimeError
|
260
|
+
end
|
261
|
+
|
262
|
+
# Error which is raised when options are invalid
|
263
|
+
class InvalidOptionsError < RuntimeError
|
264
|
+
end
|
265
|
+
|
266
|
+
# Error which is raised when a command returns an unexpected exit status (return code)
|
267
|
+
class UnexpectedExitStatusError < RuntimeError
|
268
|
+
end
|
269
|
+
|
270
|
+
# Error which is raised when command exists while input lines remain unprocessed
|
271
|
+
class UnprocessedInputError < RuntimeError
|
272
|
+
end
|
258
273
|
end
|
data/process_helper.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'process_helper
|
4
|
+
require 'process_helper'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'process_helper'
|
8
|
-
spec.version = ProcessHelper::
|
8
|
+
spec.version = ProcessHelper::PROCESS_HELPER_VERSION
|
9
9
|
spec.authors = ['Glenn Oppegard', 'Chad Woolley']
|
10
10
|
spec.email = ['oppegard@gmail.com', 'thewoolleyman@gmail.com']
|
11
11
|
spec.summary = "Makes it easier to spawn ruby sub-processes with proper capturing /
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
27
|
+
spec.add_development_dependency 'rspec-retry', '~> 0.4'
|
27
28
|
spec.add_development_dependency 'rubocop', '= 0.29.1' # exact version for static analyis libs
|
28
29
|
spec.add_development_dependency 'ruby-lint', '= 2.0.2' # exact version for static analyis libs
|
29
30
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,14 +4,18 @@ if ENV['CODECLIMATE_REPO_TOKEN']
|
|
4
4
|
end
|
5
5
|
|
6
6
|
require 'rspec'
|
7
|
+
require 'rspec/retry'
|
7
8
|
require_relative '../lib/process_helper'
|
8
9
|
|
9
10
|
RSpec::Matchers.define_negated_matcher :not_output, :output
|
10
11
|
RSpec::Matchers.define_negated_matcher :not_raise_error, :raise_error
|
11
12
|
|
12
13
|
# RSpec config
|
13
|
-
|
14
|
-
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.verbose_retry = true
|
16
|
+
config.default_retry_count = 5
|
17
|
+
config.default_sleep_interval = 1
|
18
|
+
end
|
15
19
|
|
16
20
|
# RSpec helper methods
|
17
21
|
# module SpecHelper
|
data/spec/version_spec.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glenn Oppegard
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '3.1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec-retry
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.4'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.4'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: rubocop
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,15 +122,10 @@ files:
|
|
108
122
|
- ".ruby-version"
|
109
123
|
- ".travis.yml"
|
110
124
|
- Gemfile
|
111
|
-
- LICENSE
|
112
125
|
- README.md
|
113
126
|
- Rakefile
|
127
|
+
- UNLICENSE
|
114
128
|
- lib/process_helper.rb
|
115
|
-
- lib/process_helper/empty_command_error.rb
|
116
|
-
- lib/process_helper/invalid_options_error.rb
|
117
|
-
- lib/process_helper/unexpected_exit_status_error.rb
|
118
|
-
- lib/process_helper/unprocessed_input_error.rb
|
119
|
-
- lib/process_helper/version.rb
|
120
129
|
- process_helper.gemspec
|
121
130
|
- ruby-lint.yml
|
122
131
|
- spec/error_handling_spec.rb
|