(ctx context.Context, dockerCli command.Cli, containerID string, errCh *chan error, config *container.Config, options client.ContainerAttachOptions)
| 267 | } |
| 268 | |
| 269 | func attachContainer(ctx context.Context, dockerCli command.Cli, containerID string, errCh *chan error, config *container.Config, options client.ContainerAttachOptions) (func(), error) { |
| 270 | resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options) |
| 271 | if errAttach != nil { |
| 272 | return nil, errAttach |
| 273 | } |
| 274 | |
| 275 | var ( |
| 276 | out, cerr io.Writer |
| 277 | in io.ReadCloser |
| 278 | ) |
| 279 | if options.Stdin { |
| 280 | in = dockerCli.In() |
| 281 | } |
| 282 | if options.Stdout { |
| 283 | out = dockerCli.Out() |
| 284 | } |
| 285 | if options.Stderr { |
| 286 | if config.Tty { |
| 287 | cerr = dockerCli.Out() |
| 288 | } else { |
| 289 | cerr = dockerCli.Err() |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | ch := make(chan error, 1) |
| 294 | *errCh = ch |
| 295 | |
| 296 | go func() { |
| 297 | ch <- func() error { |
| 298 | streamer := hijackedIOStreamer{ |
| 299 | streams: dockerCli, |
| 300 | inputStream: in, |
| 301 | outputStream: out, |
| 302 | errorStream: cerr, |
| 303 | resp: resp.HijackedResponse, |
| 304 | tty: config.Tty, |
| 305 | detachKeys: options.DetachKeys, |
| 306 | } |
| 307 | |
| 308 | if errHijack := streamer.stream(ctx); errHijack != nil { |
| 309 | return errHijack |
| 310 | } |
| 311 | return errAttach |
| 312 | }() |
| 313 | }() |
| 314 | return resp.HijackedResponse.Close, nil |
| 315 | } |
| 316 | |
| 317 | // withHelp decorates the error with a suggestion to use "--help". |
| 318 | func withHelp(err error, commandName string) error { |
no test coverage detected
searching dependent graphs…