(ctx context.Context, dockerCli command.Cli, execOptions *client.ExecCreateOptions, execID string)
| 137 | } |
| 138 | |
| 139 | func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *client.ExecCreateOptions, execID string) error { |
| 140 | // Interactive exec requested. |
| 141 | var ( |
| 142 | out, stderr io.Writer |
| 143 | in io.ReadCloser |
| 144 | ) |
| 145 | |
| 146 | if execOptions.AttachStdin { |
| 147 | in = dockerCli.In() |
| 148 | } |
| 149 | if execOptions.AttachStdout { |
| 150 | out = dockerCli.Out() |
| 151 | } |
| 152 | if execOptions.AttachStderr { |
| 153 | if execOptions.TTY { |
| 154 | stderr = dockerCli.Out() |
| 155 | } else { |
| 156 | stderr = dockerCli.Err() |
| 157 | } |
| 158 | } |
| 159 | fillConsoleSize(execOptions, dockerCli) |
| 160 | |
| 161 | apiClient := dockerCli.Client() |
| 162 | resp, err := apiClient.ExecAttach(ctx, execID, client.ExecAttachOptions{ |
| 163 | TTY: execOptions.TTY, |
| 164 | ConsoleSize: client.ConsoleSize{Height: execOptions.ConsoleSize.Height, Width: execOptions.ConsoleSize.Width}, |
| 165 | }) |
| 166 | if err != nil { |
| 167 | return err |
| 168 | } |
| 169 | defer resp.Close() |
| 170 | |
| 171 | errCh := make(chan error, 1) |
| 172 | |
| 173 | go func() { |
| 174 | defer close(errCh) |
| 175 | errCh <- func() error { |
| 176 | streamer := hijackedIOStreamer{ |
| 177 | streams: dockerCli, |
| 178 | inputStream: in, |
| 179 | outputStream: out, |
| 180 | errorStream: stderr, |
| 181 | resp: resp.HijackedResponse, |
| 182 | tty: execOptions.TTY, |
| 183 | detachKeys: execOptions.DetachKeys, |
| 184 | } |
| 185 | |
| 186 | return streamer.stream(ctx) |
| 187 | }() |
| 188 | }() |
| 189 | |
| 190 | if execOptions.TTY && dockerCli.In().IsTerminal() { |
| 191 | if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil { |
| 192 | _, _ = fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err) |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if err := <-errCh; err != nil { |
no test coverage detected
searching dependent graphs…