awesome_spawn 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/awesome_spawn/command_line_builder.rb +1 -3
- data/lib/awesome_spawn/command_result.rb +3 -2
- data/lib/awesome_spawn/spec_helper.rb +30 -1
- data/lib/awesome_spawn/version.rb +1 -1
- data/lib/awesome_spawn.rb +40 -4
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a45e9f8c95531c5305ea8f7d275d8ac81b458a5330787f2077c928266ce06c1
|
4
|
+
data.tar.gz: a61d2f6dfba0a30e79a3351f0776ec9c5ff8dd1ae433f42ac3d0f50b400d8a97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2bcb990402d54dc83338bf4aa85aa4a963384cdb5df6c26ff6c40d65783232a1d2425641cc892bff6b76634acf2f4fb074a02bbd15117f141b6085ddf14ffea
|
7
|
+
data.tar.gz: 1f1112bebe43856a532c0120394229ce2efebb3744b236a68ce5b8264808da11fd6f5034201937b7d2fb22071150589b1201c74182030102037388d871c75ae7
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# AwesomeSpawn
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/awesome_spawn.png)](http://badge.fury.io/rb/awesome_spawn)
|
4
|
-
[![
|
4
|
+
[![CI](https://github.com/ManageIQ/awesome_spawn/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/awesome_spawn/actions/workflows/ci.yaml)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ManageIQ/awesome_spawn.png)](https://codeclimate.com/github/ManageIQ/awesome_spawn)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/ManageIQ/awesome_spawn/badge.png?branch=master)](https://coveralls.io/r/ManageIQ/awesome_spawn)
|
7
|
-
[![Dependency Status](https://gemnasium.com/ManageIQ/awesome_spawn.png)](https://gemnasium.com/ManageIQ/awesome_spawn)
|
8
7
|
|
9
8
|
AwesomeSpawn is a module that provides some useful features over Ruby's Kernel.spawn.
|
10
9
|
|
@@ -63,9 +63,7 @@ module AwesomeSpawn
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def sanitize_associative_array(assoc_array)
|
66
|
-
assoc_array.
|
67
|
-
array.concat(sanitize_item(item))
|
68
|
-
end
|
66
|
+
assoc_array.flat_map { |item| sanitize_item(item) }
|
69
67
|
end
|
70
68
|
|
71
69
|
def sanitize_item(item)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module AwesomeSpawn
|
2
2
|
class CommandResult
|
3
|
-
attr_reader :command_line, :output, :error, :exit_status
|
3
|
+
attr_reader :command_line, :output, :error, :pid, :exit_status
|
4
4
|
|
5
|
-
def initialize(command_line, output, error, exit_status)
|
5
|
+
def initialize(command_line, output, error, pid, exit_status)
|
6
6
|
@command_line = command_line
|
7
7
|
@output = output
|
8
8
|
@error = error
|
9
|
+
@pid = pid
|
9
10
|
@exit_status = exit_status
|
10
11
|
end
|
11
12
|
|
@@ -2,6 +2,34 @@ require 'awesome_spawn'
|
|
2
2
|
|
3
3
|
module AwesomeSpawn
|
4
4
|
module SpecHelper
|
5
|
+
# Disable spawning for specs
|
6
|
+
#
|
7
|
+
# @example Disable spawning for all specs
|
8
|
+
# RSpec.configure do |config|
|
9
|
+
# AwesomeSpawn::SpecHelper.disable_spawning(config)
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# @example Disable spawning for specs in a specific path
|
13
|
+
# RSpec.configure do |config|
|
14
|
+
# AwesomeSpawn::SpecHelper.disable_spawning(config, file_path: "spec/models")
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# @param config [RSpec::Core::Configuration] RSpec configuration
|
18
|
+
# @param file_path [String] Restrict the disabling to a specific set of specs in the given path
|
19
|
+
def self.disable_spawning(config, file_path: nil)
|
20
|
+
if file_path
|
21
|
+
config.define_derived_metadata(:file_path => file_path) do |metadata|
|
22
|
+
metadata[:uses_awesome_spawn] = true
|
23
|
+
end
|
24
|
+
config.include AwesomeSpawn::SpecHelper, :uses_awesome_spawn => true
|
25
|
+
config.before(:each, :uses_awesome_spawn) { disable_spawning }
|
26
|
+
else
|
27
|
+
config.include AwesomeSpawn::SpecHelper
|
28
|
+
config.before { disable_spawning }
|
29
|
+
end
|
30
|
+
config
|
31
|
+
end
|
32
|
+
|
5
33
|
def disable_spawning
|
6
34
|
allow(Open3).to receive(:capture3)
|
7
35
|
.and_raise("Spawning is not permitted in specs. Please change your spec to use expectations/stubs.")
|
@@ -33,13 +61,14 @@ module AwesomeSpawn
|
|
33
61
|
options = options.dup
|
34
62
|
output = options.delete(:output) || ""
|
35
63
|
error = options.delete(:error) || (mode == :bad ? "Failure" : "")
|
64
|
+
pid = options.delete(:pid) || ""
|
36
65
|
exit_status = options.delete(:exit_status) || (mode == :bad ? 1 : 0)
|
37
66
|
|
38
67
|
command_line = AwesomeSpawn.build_command_line(command, options[:params])
|
39
68
|
|
40
69
|
args = [command, options]
|
41
70
|
|
42
|
-
result = CommandResult.new(command_line, output, error, exit_status)
|
71
|
+
result = CommandResult.new(command_line, output, error, pid, exit_status)
|
43
72
|
if method == :run! && mode == :bad
|
44
73
|
error_message = CommandResultError.default_message(command, exit_status)
|
45
74
|
error = CommandResultError.new(error_message, result)
|
data/lib/awesome_spawn.rb
CHANGED
@@ -17,7 +17,7 @@ module AwesomeSpawn
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Execute `command` synchronously via Kernel.spawn and gather the output
|
20
|
-
# stream, error stream, and exit status in a {CommandResult}.
|
20
|
+
# stream, error stream, pid, and exit status in a {CommandResult}.
|
21
21
|
#
|
22
22
|
# @example With normal output
|
23
23
|
# result = AwesomeSpawn.run('echo Hi')
|
@@ -77,12 +77,15 @@ module AwesomeSpawn
|
|
77
77
|
options[:stdin_data] = in_data
|
78
78
|
end
|
79
79
|
|
80
|
-
output, error,
|
80
|
+
output, error, process_status = launch(env, command_line, options)
|
81
|
+
status = process_status && process_status.exitstatus
|
82
|
+
pid = process_status.pid if process_status
|
83
|
+
|
81
84
|
rescue Errno::ENOENT => err
|
82
85
|
raise NoSuchFileError.new(err.message) if NoSuchFileError.detected?(err.message)
|
83
86
|
raise
|
84
87
|
else
|
85
|
-
CommandResult.new(command_line, output, error, status)
|
88
|
+
CommandResult.new(command_line, output, error, pid, status)
|
86
89
|
end
|
87
90
|
|
88
91
|
# Same as {#run}, additionally raising a {CommandResultError} if the exit
|
@@ -111,6 +114,35 @@ module AwesomeSpawn
|
|
111
114
|
command_result
|
112
115
|
end
|
113
116
|
|
117
|
+
# Execute `command` in a detached manner
|
118
|
+
# The defalt is to spawn a new child process that sends the output to the null device
|
119
|
+
# @param [String] command the command to execute
|
120
|
+
# @param [Hash{Symbol,Object}] options the Kernel.spawn options
|
121
|
+
# by default the :err, and :out are redirected to the null device.
|
122
|
+
# For windows, default :pgroup_new is true (make a root process of a new process group)
|
123
|
+
# For others, default :pgroup is true (make a new process group)
|
124
|
+
# @returns [Integer] pid of new process
|
125
|
+
#
|
126
|
+
# @example With normal output
|
127
|
+
# AwesomeSpawn.run_detached('echo "Hi" > /tmp/out')
|
128
|
+
# # => 79901
|
129
|
+
#
|
130
|
+
# if a user defines :out or :err, it is assumed they will define both
|
131
|
+
def run_detached(command, options = {})
|
132
|
+
env, command_line, options = parse_command_options(command, options)
|
133
|
+
# maybe add support later for this
|
134
|
+
raise ArgumentError, "options cannot contain :in_data" if options.include?(:in_data)
|
135
|
+
|
136
|
+
options[[:out, :err]] = [IO::NULL, "w"] unless (options.keys.flatten & [:out, :err]).any?
|
137
|
+
if Gem.win_platform?
|
138
|
+
options[:new_pgroup] = true unless options.key?(:new_pgroup)
|
139
|
+
else
|
140
|
+
options[:pgroup] = true unless options.key?(:pgroup)
|
141
|
+
end
|
142
|
+
|
143
|
+
detach(env, command_line, options)
|
144
|
+
end
|
145
|
+
|
114
146
|
# (see CommandLineBuilder#build)
|
115
147
|
def build_command_line(command, params = nil)
|
116
148
|
CommandLineBuilder.new.build(command, params)
|
@@ -126,7 +158,7 @@ module AwesomeSpawn
|
|
126
158
|
else
|
127
159
|
output, error, status = Open3.capture3(env, command, spawn_options)
|
128
160
|
end
|
129
|
-
return output, error, status
|
161
|
+
return output, error, status
|
130
162
|
end
|
131
163
|
|
132
164
|
def parse_command_options(command, options)
|
@@ -136,4 +168,8 @@ module AwesomeSpawn
|
|
136
168
|
|
137
169
|
[env, build_command_line(command, params), options]
|
138
170
|
end
|
171
|
+
|
172
|
+
def detach(env, command, options)
|
173
|
+
Process.detach(Kernel.spawn(env, command, options)).pid
|
174
|
+
end
|
139
175
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_spawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
8
8
|
- Brandon Dunne
|
9
9
|
- Joe Rafaniello
|
10
10
|
- Mo Morsi
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2023-11-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: manageiq-style
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
45
|
+
name: rake
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
59
|
+
name: rspec
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
@@ -69,6 +69,20 @@ dependencies:
|
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: simplecov
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.21.2
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.21.2
|
72
86
|
description: AwesomeSpawn is a module that provides some useful features over Ruby's
|
73
87
|
Kernel.spawn.
|
74
88
|
email:
|
@@ -95,7 +109,7 @@ homepage: https://github.com/ManageIQ/awesome_spawn
|
|
95
109
|
licenses:
|
96
110
|
- MIT
|
97
111
|
metadata: {}
|
98
|
-
post_install_message:
|
112
|
+
post_install_message:
|
99
113
|
rdoc_options: []
|
100
114
|
require_paths:
|
101
115
|
- lib
|
@@ -110,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '0'
|
112
126
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
114
|
-
signing_key:
|
127
|
+
rubygems_version: 3.4.20
|
128
|
+
signing_key:
|
115
129
|
specification_version: 4
|
116
130
|
summary: AwesomeSpawn is a module that provides some useful features over Ruby's Kernel.spawn.
|
117
131
|
test_files: []
|