Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 6 additions & 21 deletions cli/command/container/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,18 @@ package container
import (
"context"
"io"
"reflect"
"net/http"
"strings"
"unsafe"

"github.com/moby/moby/client"
)

func mockContainerExportResult(content string) client.ContainerExportResult {
out := client.ContainerExportResult{}

// Set unexported field "rc"
v := reflect.ValueOf(&out).Elem()
f := v.FieldByName("rc")
r := io.NopCloser(strings.NewReader(content))
reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem().Set(reflect.ValueOf(r))
return out
return io.NopCloser(strings.NewReader(content))
}

func mockContainerLogsResult(content string) client.ContainerLogsResult {
out := client.ContainerLogsResult{}

// Set unexported field "rc"
v := reflect.ValueOf(&out).Elem()
f := v.FieldByName("rc")
r := io.NopCloser(strings.NewReader(content))
reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem().Set(reflect.ValueOf(r))
return out
return io.NopCloser(strings.NewReader(content))
}

type fakeStreamResult struct {
Expand Down Expand Up @@ -147,7 +132,7 @@ func (f *fakeClient) ContainerLogs(_ context.Context, containerID string, option
if f.logFunc != nil {
return f.logFunc(containerID, options)
}
return client.ContainerLogsResult{}, nil
return http.NoBody, nil
}

func (f *fakeClient) ClientVersion() string {
Expand All @@ -172,7 +157,7 @@ func (f *fakeClient) ContainerExport(_ context.Context, containerID string, _ cl
if f.containerExportFunc != nil {
return f.containerExportFunc(containerID)
}
return client.ContainerExportResult{}, nil
return http.NoBody, nil
}

func (f *fakeClient) ExecResize(_ context.Context, id string, options client.ExecResizeOptions) (client.ExecResizeResult, error) {
Expand All @@ -189,7 +174,7 @@ func (f *fakeClient) ContainerKill(ctx context.Context, containerID string, opti
return client.ContainerKillResult{}, nil
}

func (f *fakeClient) ContainersPrune(ctx context.Context, options client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
func (f *fakeClient) ContainerPrune(ctx context.Context, options client.ContainerPruneOptions) (client.ContainerPruneResult, error) {
if f.containerPruneFunc != nil {
return f.containerPruneFunc(ctx, options)
}
Expand Down
36 changes: 11 additions & 25 deletions cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin
return err
}
if !options.Detach {
if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.Tty); err != nil {
if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.TTY); err != nil {
return err
}
}
Expand All @@ -119,27 +119,20 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin
}

if options.Detach {
var cs client.ConsoleSize
if execOptions.ConsoleSize != nil {
cs = client.ConsoleSize{
Height: execOptions.ConsoleSize[0],
Width: execOptions.ConsoleSize[1],
}
}
_, err := apiClient.ExecStart(ctx, execID, client.ExecStartOptions{
Detach: options.Detach,
TTY: execOptions.Tty,
ConsoleSize: cs,
TTY: execOptions.TTY,
ConsoleSize: client.ConsoleSize{Height: execOptions.ConsoleSize.Height, Width: execOptions.ConsoleSize.Width},
})
return err
}
return interactiveExec(ctx, dockerCLI, execOptions, execID)
}

func fillConsoleSize(execOptions *client.ExecCreateOptions, dockerCli command.Cli) {
if execOptions.Tty {
if execOptions.TTY {
height, width := dockerCli.Out().GetTtySize()
execOptions.ConsoleSize = &[2]uint{height, width}
execOptions.ConsoleSize = client.ConsoleSize{Height: height, Width: width}
}
}

Expand All @@ -157,7 +150,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *cl
out = dockerCli.Out()
}
if execOptions.AttachStderr {
if execOptions.Tty {
if execOptions.TTY {
stderr = dockerCli.Out()
} else {
stderr = dockerCli.Err()
Expand All @@ -166,16 +159,9 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *cl
fillConsoleSize(execOptions, dockerCli)

apiClient := dockerCli.Client()
var cs client.ConsoleSize
if execOptions.ConsoleSize != nil {
cs = client.ConsoleSize{
Height: execOptions.ConsoleSize[0],
Width: execOptions.ConsoleSize[1],
}
}
resp, err := apiClient.ExecAttach(ctx, execID, client.ExecAttachOptions{
TTY: execOptions.Tty,
ConsoleSize: cs,
TTY: execOptions.TTY,
ConsoleSize: client.ConsoleSize{Height: execOptions.ConsoleSize.Height, Width: execOptions.ConsoleSize.Width},
})
if err != nil {
return err
Expand All @@ -193,15 +179,15 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *cl
outputStream: out,
errorStream: stderr,
resp: resp.HijackedResponse,
tty: execOptions.Tty,
tty: execOptions.TTY,
detachKeys: execOptions.DetachKeys,
}

return streamer.stream(ctx)
}()
}()

if execOptions.Tty && dockerCli.In().IsTerminal() {
if execOptions.TTY && dockerCli.In().IsTerminal() {
if err := MonitorTtySize(ctx, dockerCli, execID, true); err != nil {
_, _ = fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err)
}
Expand Down Expand Up @@ -237,7 +223,7 @@ func parseExec(execOpts ExecOptions, configFile *configfile.ConfigFile) (*client
execOptions := &client.ExecCreateOptions{
User: execOpts.User,
Privileged: execOpts.Privileged,
Tty: execOpts.TTY,
TTY: execOpts.TTY,
Cmd: execOpts.Command,
WorkingDir: execOpts.Workdir,
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TWO=2
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
Tty: true,
TTY: true,
Cmd: []string{"command"},
},
},
Expand All @@ -86,7 +86,7 @@ TWO=2
Detach: true,
}),
expected: client.ExecCreateOptions{
Tty: true,
TTY: true,
Cmd: []string{"command"},
},
},
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
}
}

res, err := dockerCli.Client().ContainersPrune(ctx, client.ContainerPruneOptions{
res, err := dockerCli.Client().ContainerPrune(ctx, client.ContainerPruneOptions{
Filters: pruneFilters,
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cli/command/formatter/buildcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ shared: {{.Shared}}
return Format(source)
}

func buildCacheSort(buildCache []*build.CacheRecord) {
func buildCacheSort(buildCache []build.CacheRecord) {
sort.Slice(buildCache, func(i, j int) bool {
lui, luj := buildCache[i].LastUsedAt, buildCache[j].LastUsedAt
switch {
Expand All @@ -70,7 +70,7 @@ func buildCacheSort(buildCache []*build.CacheRecord) {
}

// BuildCacheWrite renders the context for a list of containers
func BuildCacheWrite(ctx Context, buildCaches []*build.CacheRecord) error {
func BuildCacheWrite(ctx Context, buildCaches []build.CacheRecord) error {
render := func(format func(subContext SubContext) error) error {
buildCacheSort(buildCaches)
for _, bc := range buildCaches {
Expand All @@ -87,7 +87,7 @@ func BuildCacheWrite(ctx Context, buildCaches []*build.CacheRecord) error {
type buildCacheContext struct {
HeaderContext
trunc bool
v *build.CacheRecord
v build.CacheRecord
}

func newBuildCacheContext() *buildCacheContext {
Expand Down
Loading
Loading