mirror of https://github.com/docker/cli.git
Merge pull request #1718 from ijc/dial-stdio-npipe-on-windows
dial-stdio: handle connections which lack CloseRead method.
This commit is contained in:
commit
d6a230606c
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
|
@ -75,11 +74,7 @@ func PersistentPreRunE(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
// flags must be the original top-level command flags, not cmd.Flags()
|
||||
options.opts.Common.SetDefaultOptions(options.flags)
|
||||
var initopts []command.InitializeOpt
|
||||
if runtime.GOOS != "windows" {
|
||||
initopts = append(initopts, withPluginClientConn(options.name))
|
||||
}
|
||||
err = options.dockerCli.Initialize(options.opts, initopts...)
|
||||
err = options.dockerCli.Initialize(options.opts, withPluginClientConn(options.name))
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -21,12 +19,8 @@ func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
|
|||
NewInfoCommand(dockerCli),
|
||||
newDiskUsageCommand(dockerCli),
|
||||
newPruneCommand(dockerCli),
|
||||
)
|
||||
if runtime.GOOS != "windows" {
|
||||
cmd.AddCommand(
|
||||
newDialStdioCommand(dockerCli),
|
||||
)
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -34,10 +34,18 @@ func runDialStdio(dockerCli command.Cli) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "failed to open the raw stream connection")
|
||||
}
|
||||
connHalfCloser, ok := conn.(halfCloser)
|
||||
if !ok {
|
||||
defer conn.Close()
|
||||
|
||||
var connHalfCloser halfCloser
|
||||
switch t := conn.(type) {
|
||||
case halfCloser:
|
||||
connHalfCloser = t
|
||||
case halfReadWriteCloser:
|
||||
connHalfCloser = &nopCloseReader{t}
|
||||
default:
|
||||
return errors.New("the raw stream connection does not implement halfCloser")
|
||||
}
|
||||
|
||||
stdin2conn := make(chan error)
|
||||
conn2stdout := make(chan error)
|
||||
go func() {
|
||||
|
@ -90,6 +98,19 @@ type halfCloser interface {
|
|||
halfWriteCloser
|
||||
}
|
||||
|
||||
type halfReadWriteCloser interface {
|
||||
io.Reader
|
||||
halfWriteCloser
|
||||
}
|
||||
|
||||
type nopCloseReader struct {
|
||||
halfReadWriteCloser
|
||||
}
|
||||
|
||||
func (x *nopCloseReader) CloseRead() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type halfReadCloserWrapper struct {
|
||||
io.ReadCloser
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue