wslc-wip 1.1.1 → 1.1.2
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/lib/wip/command_runner.rb +50 -2
- data/lib/wip/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37c2e70c286c4dd7b163201674eff9b4111fbe3f05ef032500a5b7ac516f97b5
|
|
4
|
+
data.tar.gz: fbad7b94e10bb0cbd9efc8c70f1a2546830ac0c20f276a925b48e0d668679902
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70319980be04f8abdbb6d5e167e8941ca4fa3a8ab65b0cd71ec884daff639205a70935b4c5a756ec3403678982c2859423051930379aa3d79f302506b0f88326
|
|
7
|
+
data.tar.gz: f100b5622d566ab77da4437cb028138a7fa33f47d4d19ff70874c683e2995e9c3213bc95b0109c03c82556827a26ee22b47a034bf7fc96895effc2c8fcb3950f
|
data/lib/wip/command_runner.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'open3'
|
|
4
|
-
require 'pty'
|
|
4
|
+
require 'pty' unless Gem.win_platform?
|
|
5
5
|
require 'io/console'
|
|
6
6
|
|
|
7
7
|
module Wip
|
|
@@ -18,7 +18,7 @@ module Wip
|
|
|
18
18
|
|
|
19
19
|
def run(command, env: {}, interactive: false, chdir: nil)
|
|
20
20
|
@stderr.puts "+ #{CommandDisplay.for_debug(command)}" if @debug
|
|
21
|
-
return
|
|
21
|
+
return run_interactive(command, env, chdir) if interactive
|
|
22
22
|
|
|
23
23
|
opts = chdir ? { chdir: chdir } : {}
|
|
24
24
|
captured = +''
|
|
@@ -41,6 +41,10 @@ module Wip
|
|
|
41
41
|
|
|
42
42
|
private
|
|
43
43
|
|
|
44
|
+
def run_interactive(command, env, chdir)
|
|
45
|
+
Gem.win_platform? ? run_inherited(command, env, chdir) : run_attached(command, env, chdir)
|
|
46
|
+
end
|
|
47
|
+
|
|
44
48
|
# exitstatus is nil when the process was killed by a signal instead of
|
|
45
49
|
# exiting normally; fall back to the conventional 128+signal shell code
|
|
46
50
|
# so callers always get a comparable integer.
|
|
@@ -82,6 +86,50 @@ module Wip
|
|
|
82
86
|
130
|
|
83
87
|
end
|
|
84
88
|
|
|
89
|
+
# Ruby's PTY library wraps openpty(3), which native Windows builds don't
|
|
90
|
+
# ship (require 'pty' is skipped there entirely, see the top of this
|
|
91
|
+
# file). Fall back to letting the child inherit wip's real stdio
|
|
92
|
+
# directly, same as `run` would've done pre-pty for the piped case: it
|
|
93
|
+
# still gives the child a real console (job control, Ctrl-C, isatty
|
|
94
|
+
# rendering all work), just without a way for wip to see the output, so
|
|
95
|
+
# report_hint can't run on failure here.
|
|
96
|
+
def run_inherited(command, env, chdir)
|
|
97
|
+
opts = chdir ? { chdir: chdir } : {}
|
|
98
|
+
opts[:in] = @stdin if io_stream?(@stdin)
|
|
99
|
+
opts[:out] = @stdout if io_stream?(@stdout)
|
|
100
|
+
opts[:err] = @stderr if io_stream?(@stderr)
|
|
101
|
+
pid = nil
|
|
102
|
+
pid = Process.spawn(env, *command, opts)
|
|
103
|
+
_, status = Process.wait2(pid)
|
|
104
|
+
exitstatus(status)
|
|
105
|
+
rescue Errno::ENOENT => e
|
|
106
|
+
@stderr.puts e.message
|
|
107
|
+
127
|
|
108
|
+
rescue Interrupt
|
|
109
|
+
reap_interrupted_child(pid)
|
|
110
|
+
@stderr.puts "\nwip: interrupted"
|
|
111
|
+
130
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Process.spawn can only redirect to real OS-backed streams (an IO, or
|
|
115
|
+
# something that wraps one via to_io) — StringIO and friends (used by
|
|
116
|
+
# tests, and by wip's own quiet/capture modes) aren't valid redirection
|
|
117
|
+
# targets. Fall back to the process's own inherited fds for those rather
|
|
118
|
+
# than passing them through and having Process.spawn reject them.
|
|
119
|
+
def io_stream?(stream) = stream.respond_to?(:to_io)
|
|
120
|
+
|
|
121
|
+
# The child shares wip's real controlling terminal here (unlike the pty
|
|
122
|
+
# path), so it already received the same Ctrl-C the terminal delivered to
|
|
123
|
+
# wip; there's nothing to kill, just something to reap so it doesn't
|
|
124
|
+
# linger as a zombie once wip moves on.
|
|
125
|
+
def reap_interrupted_child(pid)
|
|
126
|
+
return unless pid
|
|
127
|
+
|
|
128
|
+
Process.wait2(pid)
|
|
129
|
+
rescue Errno::ECHILD, Interrupt
|
|
130
|
+
nil
|
|
131
|
+
end
|
|
132
|
+
|
|
85
133
|
def pump_attached(output, input, captured)
|
|
86
134
|
stdin_thread = forward_stdin(input)
|
|
87
135
|
loop do
|
data/lib/wip/version.rb
CHANGED