Skip to content

Commit dff0dc8

Browse files
authored
Merge pull request #5790 from thaJeztah/leftover_cleanups
cli/command: some minor cleanups
2 parents 7c3fa81 + 632f179 commit dff0dc8

7 files changed

Lines changed: 47 additions & 49 deletions

File tree

cli/command/config/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func newConfigCreateCommand(dockerCli command.Cli) *cobra.Command {
4848
}
4949

5050
// RunConfigCreate creates a config with the given options.
51-
func RunConfigCreate(ctx context.Context, dockerCli command.Cli, options CreateOptions) error {
52-
client := dockerCli.Client()
51+
func RunConfigCreate(ctx context.Context, dockerCLI command.Cli, options CreateOptions) error {
52+
apiClient := dockerCLI.Client()
5353

54-
var in io.Reader = dockerCli.In()
54+
var in io.Reader = dockerCLI.In()
5555
if options.File != "-" {
5656
file, err := sequential.Open(options.File)
5757
if err != nil {
@@ -78,11 +78,11 @@ func RunConfigCreate(ctx context.Context, dockerCli command.Cli, options CreateO
7878
Name: options.TemplateDriver,
7979
}
8080
}
81-
r, err := client.ConfigCreate(ctx, spec)
81+
r, err := apiClient.ConfigCreate(ctx, spec)
8282
if err != nil {
8383
return err
8484
}
8585

86-
fmt.Fprintln(dockerCli.Out(), r.ID)
86+
fmt.Fprintln(dockerCLI.Out(), r.ID)
8787
return nil
8888
}

cli/command/config/inspect.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func newConfigInspectCommand(dockerCli command.Cli) *cobra.Command {
4343
}
4444

4545
// RunConfigInspect inspects the given Swarm config.
46-
func RunConfigInspect(ctx context.Context, dockerCli command.Cli, opts InspectOptions) error {
47-
client := dockerCli.Client()
46+
func RunConfigInspect(ctx context.Context, dockerCLI command.Cli, opts InspectOptions) error {
47+
apiClient := dockerCLI.Client()
4848

4949
if opts.Pretty {
5050
opts.Format = "pretty"
5151
}
5252

5353
getRef := func(id string) (any, []byte, error) {
54-
return client.ConfigInspectWithRaw(ctx, id)
54+
return apiClient.ConfigInspectWithRaw(ctx, id)
5555
}
5656
f := opts.Format
5757

@@ -62,7 +62,7 @@ func RunConfigInspect(ctx context.Context, dockerCli command.Cli, opts InspectOp
6262
}
6363

6464
configCtx := formatter.Context{
65-
Output: dockerCli.Out(),
65+
Output: dockerCLI.Out(),
6666
Format: NewFormat(f, false),
6767
}
6868

cli/command/config/ls.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ func newConfigListCommand(dockerCli command.Cli) *cobra.Command {
4545
}
4646

4747
// RunConfigList lists Swarm configs.
48-
func RunConfigList(ctx context.Context, dockerCli command.Cli, options ListOptions) error {
49-
client := dockerCli.Client()
48+
func RunConfigList(ctx context.Context, dockerCLI command.Cli, options ListOptions) error {
49+
apiClient := dockerCLI.Client()
5050

51-
configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: options.Filter.Value()})
51+
configs, err := apiClient.ConfigList(ctx, types.ConfigListOptions{Filters: options.Filter.Value()})
5252
if err != nil {
5353
return err
5454
}
5555

5656
format := options.Format
5757
if len(format) == 0 {
58-
if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
59-
format = dockerCli.ConfigFile().ConfigFormat
58+
if len(dockerCLI.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
59+
format = dockerCLI.ConfigFile().ConfigFormat
6060
} else {
6161
format = formatter.TableFormatKey
6262
}
@@ -67,7 +67,7 @@ func RunConfigList(ctx context.Context, dockerCli command.Cli, options ListOptio
6767
})
6868

6969
configCtx := formatter.Context{
70-
Output: dockerCli.Out(),
70+
Output: dockerCLI.Out(),
7171
Format: NewFormat(format, options.Quiet),
7272
}
7373
return FormatWrite(configCtx, configs)

cli/command/container/cp.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func resolveLocalPath(localPath string) (absPath string, err error) {
208208
return archive.PreserveTrailingDotOrSeparator(absPath, localPath), nil
209209
}
210210

211-
func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpConfig) (err error) {
211+
func copyFromContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) {
212212
dstPath := copyConfig.destPath
213213
srcPath := copyConfig.sourcePath
214214

@@ -224,11 +224,11 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
224224
return err
225225
}
226226

227-
client := dockerCli.Client()
227+
apiClient := dockerCLI.Client()
228228
// if client requests to follow symbol link, then must decide target file to be copied
229229
var rebaseName string
230230
if copyConfig.followLink {
231-
srcStat, err := client.ContainerStatPath(ctx, copyConfig.container, srcPath)
231+
srcStat, err := apiClient.ContainerStatPath(ctx, copyConfig.container, srcPath)
232232

233233
// If the destination is a symbolic link, we should follow it.
234234
if err == nil && srcStat.Mode&os.ModeSymlink != 0 {
@@ -247,14 +247,14 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
247247
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
248248
defer cancel()
249249

250-
content, stat, err := client.CopyFromContainer(ctx, copyConfig.container, srcPath)
250+
content, stat, err := apiClient.CopyFromContainer(ctx, copyConfig.container, srcPath)
251251
if err != nil {
252252
return err
253253
}
254254
defer content.Close()
255255

256256
if dstPath == "-" {
257-
_, err = io.Copy(dockerCli.Out(), content)
257+
_, err = io.Copy(dockerCLI.Out(), content)
258258
return err
259259
}
260260

@@ -283,12 +283,12 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
283283
return archive.CopyTo(preArchive, srcInfo, dstPath)
284284
}
285285

286-
restore, done := copyProgress(ctx, dockerCli.Err(), copyFromContainerHeader, &copiedSize)
286+
restore, done := copyProgress(ctx, dockerCLI.Err(), copyFromContainerHeader, &copiedSize)
287287
res := archive.CopyTo(preArchive, srcInfo, dstPath)
288288
cancel()
289289
<-done
290290
restore()
291-
fmt.Fprintln(dockerCli.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", dstPath)
291+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", dstPath)
292292

293293
return res
294294
}
@@ -297,7 +297,7 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
297297
// about both the source and destination. The API is a simple tar
298298
// archive/extract API but we can use the stat info header about the
299299
// destination to be more informed about exactly what the destination is.
300-
func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpConfig) (err error) {
300+
func copyToContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) {
301301
srcPath := copyConfig.sourcePath
302302
dstPath := copyConfig.destPath
303303

@@ -309,10 +309,10 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
309309
}
310310
}
311311

312-
client := dockerCli.Client()
312+
apiClient := dockerCLI.Client()
313313
// Prepare destination copy info by stat-ing the container path.
314314
dstInfo := archive.CopyInfo{Path: dstPath}
315-
dstStat, err := client.ContainerStatPath(ctx, copyConfig.container, dstPath)
315+
dstStat, err := apiClient.ContainerStatPath(ctx, copyConfig.container, dstPath)
316316

317317
// If the destination is a symbolic link, we should evaluate it.
318318
if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
@@ -324,7 +324,8 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
324324
}
325325

326326
dstInfo.Path = linkTarget
327-
dstStat, err = client.ContainerStatPath(ctx, copyConfig.container, linkTarget)
327+
dstStat, err = apiClient.ContainerStatPath(ctx, copyConfig.container, linkTarget)
328+
// FIXME(thaJeztah): unhandled error (should this return?)
328329
}
329330

330331
// Validate the destination path
@@ -401,16 +402,16 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
401402
}
402403

403404
if copyConfig.quiet {
404-
return client.CopyToContainer(ctx, copyConfig.container, resolvedDstPath, content, options)
405+
return apiClient.CopyToContainer(ctx, copyConfig.container, resolvedDstPath, content, options)
405406
}
406407

407408
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
408-
restore, done := copyProgress(ctx, dockerCli.Err(), copyToContainerHeader, &copiedSize)
409-
res := client.CopyToContainer(ctx, copyConfig.container, resolvedDstPath, content, options)
409+
restore, done := copyProgress(ctx, dockerCLI.Err(), copyToContainerHeader, &copiedSize)
410+
res := apiClient.CopyToContainer(ctx, copyConfig.container, resolvedDstPath, content, options)
410411
cancel()
411412
<-done
412413
restore()
413-
fmt.Fprintln(dockerCli.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", copyConfig.container+":"+dstInfo.Path)
414+
fmt.Fprintln(dockerCLI.Err(), "Successfully copied", progressHumanSize(copiedSize), "to", copyConfig.container+":"+dstInfo.Path)
414415

415416
return res
416417
}

cli/command/container/exec.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command {
8484
}
8585

8686
// RunExec executes an `exec` command
87-
func RunExec(ctx context.Context, dockerCli command.Cli, containerIDorName string, options ExecOptions) error {
88-
execOptions, err := parseExec(options, dockerCli.ConfigFile())
87+
func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName string, options ExecOptions) error {
88+
execOptions, err := parseExec(options, dockerCLI.ConfigFile())
8989
if err != nil {
9090
return err
9191
}
9292

93-
apiClient := dockerCli.Client()
93+
apiClient := dockerCLI.Client()
9494

9595
// We need to check the tty _before_ we do the ContainerExecCreate, because
9696
// otherwise if we error out we will leak execIDs on the server (and
@@ -100,12 +100,12 @@ func RunExec(ctx context.Context, dockerCli command.Cli, containerIDorName strin
100100
return err
101101
}
102102
if !execOptions.Detach {
103-
if err := dockerCli.In().CheckTty(execOptions.AttachStdin, execOptions.Tty); err != nil {
103+
if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.Tty); err != nil {
104104
return err
105105
}
106106
}
107107

108-
fillConsoleSize(execOptions, dockerCli)
108+
fillConsoleSize(execOptions, dockerCLI)
109109

110110
response, err := apiClient.ContainerExecCreate(ctx, containerIDorName, *execOptions)
111111
if err != nil {
@@ -124,7 +124,7 @@ func RunExec(ctx context.Context, dockerCli command.Cli, containerIDorName strin
124124
ConsoleSize: execOptions.ConsoleSize,
125125
})
126126
}
127-
return interactiveExec(ctx, dockerCli, execOptions, execID)
127+
return interactiveExec(ctx, dockerCLI, execOptions, execID)
128128
}
129129

130130
func fillConsoleSize(execOptions *container.ExecOptions, dockerCli command.Cli) {

cli/command/container/inspect.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command {
4242
return cmd
4343
}
4444

45-
func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error {
46-
client := dockerCli.Client()
47-
48-
getRefFunc := func(ref string) (any, []byte, error) {
49-
return client.ContainerInspectWithRaw(ctx, ref, opts.size)
50-
}
51-
return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc)
45+
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
46+
apiClient := dockerCLI.Client()
47+
return inspect.Inspect(dockerCLI.Out(), opts.refs, opts.format, func(ref string) (any, []byte, error) {
48+
return apiClient.ContainerInspectWithRaw(ctx, ref, opts.size)
49+
})
5250
}

cli/command/image/inspect.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command {
3939
return cmd
4040
}
4141

42-
func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) error {
43-
client := dockerCli.Client()
44-
getRefFunc := func(ref string) (any, []byte, error) {
45-
return client.ImageInspectWithRaw(ctx, ref)
46-
}
47-
return inspect.Inspect(dockerCli.Out(), opts.refs, opts.format, getRefFunc)
42+
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
43+
apiClient := dockerCLI.Client()
44+
return inspect.Inspect(dockerCLI.Out(), opts.refs, opts.format, func(ref string) (any, []byte, error) {
45+
return apiClient.ImageInspectWithRaw(ctx, ref)
46+
})
4847
}

0 commit comments

Comments
 (0)