Skip to content

Commit 46953cc

Browse files
authored
Simplify commandFactory.buildVirtual (#602)
In the case of `virtualCommand`, `stdin` is wrapped in `readCloser` and it should be returned to any other struct that depends on `virtualCommand`. `base.stdin` should stay unchanged.
1 parent 9b62370 commit 46953cc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

internal/command/command_virtual.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (c *virtualCommand) Pid() int {
4949
return c.cmd.Process.Pid
5050
}
5151

52+
func (c *virtualCommand) Stdin() io.Reader {
53+
return c.stdin
54+
}
55+
5256
func (c *virtualCommand) Start(ctx context.Context) (err error) {
5357
c.pty, c.tty, err = pty.Open()
5458
if err != nil {

internal/command/factory.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,9 @@ func (f *commandFactory) buildNative(base *base) internalCommand {
173173

174174
func (f *commandFactory) buildVirtual(base *base, opts CommandOptions) internalCommand {
175175
var stdin io.ReadCloser
176-
177-
if !isNil(base.Stdin()) {
178-
stdin = &readCloser{r: base.Stdin(), done: make(chan struct{})}
179-
base.stdin = stdin
176+
if in := base.Stdin(); !isNil(in) {
177+
stdin = &readCloser{r: in, done: make(chan struct{})}
180178
}
181-
182179
return &virtualCommand{
183180
base: base,
184181
isEchoEnabled: opts.EnableEcho,

0 commit comments

Comments
 (0)