Skip to content

Commit

Permalink
Simplify commandFactory.buildVirtual (#602)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adambabik authored Jun 4, 2024
1 parent 9b62370 commit 46953cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions internal/command/command_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (c *virtualCommand) Pid() int {
return c.cmd.Process.Pid
}

func (c *virtualCommand) Stdin() io.Reader {
return c.stdin
}

func (c *virtualCommand) Start(ctx context.Context) (err error) {
c.pty, c.tty, err = pty.Open()
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions internal/command/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,9 @@ func (f *commandFactory) buildNative(base *base) internalCommand {

func (f *commandFactory) buildVirtual(base *base, opts CommandOptions) internalCommand {
var stdin io.ReadCloser

if !isNil(base.Stdin()) {
stdin = &readCloser{r: base.Stdin(), done: make(chan struct{})}
base.stdin = stdin
if in := base.Stdin(); !isNil(in) {
stdin = &readCloser{r: in, done: make(chan struct{})}
}

return &virtualCommand{
base: base,
isEchoEnabled: opts.EnableEcho,
Expand Down

0 comments on commit 46953cc

Please sign in to comment.