Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move CloseStdin into clibase
  • Loading branch information
ammario committed Jun 9, 2023
commit 65cdbcc6da7ec699046083d950ed7b6c45b7cadb
10 changes: 10 additions & 0 deletions cli/clibase/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ func (inv *Invocation) run(state *runState) error {
return nil
}

// CloseStdin closes the invocation's Stdin if it is an io.Closer.
func (inv *Invocation) CloseStdin() error {
// If we don't close Stdin, the io.Copy below may
// block indefinitely on Stdin Read.
if rc, ok := inv.Stdin.(io.Closer); ok {
return rc.Close()
}
return nil
}

type RunCommandError struct {
Cmd *Cmd
Err error
Expand Down
4 changes: 1 addition & 3 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
rawSSH.Close()
// If we don't close Stdin, the io.Copy below may
// block indefinitely on Stdin Read.
if rc, ok := inv.Stdin.(io.Closer); ok {
rc.Close()
}
_ = inv.CloseStdin()
return nil
}, logger, client, workspace)
}()
Expand Down