Skip to content

Commit 65cdbcc

Browse files
committed
Move CloseStdin into clibase
1 parent 5a311b3 commit 65cdbcc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cli/clibase/cmd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ func (inv *Invocation) run(state *runState) error {
381381
return nil
382382
}
383383

384+
// CloseStdin closes the invocation's Stdin if it is an io.Closer.
385+
func (inv *Invocation) CloseStdin() error {
386+
// If we don't close Stdin, the io.Copy below may
387+
// block indefinitely on Stdin Read.
388+
if rc, ok := inv.Stdin.(io.Closer); ok {
389+
return rc.Close()
390+
}
391+
return nil
392+
}
393+
384394
type RunCommandError struct {
385395
Cmd *Cmd
386396
Err error

cli/ssh.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
193193
rawSSH.Close()
194194
// If we don't close Stdin, the io.Copy below may
195195
// block indefinitely on Stdin Read.
196-
if rc, ok := inv.Stdin.(io.Closer); ok {
197-
rc.Close()
198-
}
196+
_ = inv.CloseStdin()
199197
return nil
200198
}, logger, client, workspace)
201199
}()

0 commit comments

Comments
 (0)