Skip to content

Commit 980b856

Browse files
authored
Merge pull request #6183 from thaJeztah/diff_simplify
cli/command/container: diff: remove redundant validation and cleanup
2 parents 9c25614 + 0f2b709 commit 980b856

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

cli/command/container/diff.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ import (
77
"github.com/docker/cli/cli/command"
88
"github.com/docker/cli/cli/command/completion"
99
"github.com/docker/cli/cli/command/formatter"
10-
"github.com/pkg/errors"
1110
"github.com/spf13/cobra"
1211
)
1312

14-
type diffOptions struct {
15-
container string
16-
}
17-
1813
// NewDiffCommand creates a new cobra.Command for `docker diff`
1914
func NewDiffCommand(dockerCli command.Cli) *cobra.Command {
20-
var opts diffOptions
21-
2215
return &cobra.Command{
2316
Use: "diff CONTAINER",
2417
Short: "Inspect changes to files or directories on a container's filesystem",
2518
Args: cli.ExactArgs(1),
2619
RunE: func(cmd *cobra.Command, args []string) error {
27-
opts.container = args[0]
28-
return runDiff(cmd.Context(), dockerCli, &opts)
20+
return runDiff(cmd.Context(), dockerCli, args[0])
2921
},
3022
Annotations: map[string]string{
3123
"aliases": "docker container diff, docker diff",
@@ -34,16 +26,13 @@ func NewDiffCommand(dockerCli command.Cli) *cobra.Command {
3426
}
3527
}
3628

37-
func runDiff(ctx context.Context, dockerCli command.Cli, opts *diffOptions) error {
38-
if opts.container == "" {
39-
return errors.New("Container name cannot be empty")
40-
}
41-
changes, err := dockerCli.Client().ContainerDiff(ctx, opts.container)
29+
func runDiff(ctx context.Context, dockerCLI command.Cli, containerID string) error {
30+
changes, err := dockerCLI.Client().ContainerDiff(ctx, containerID)
4231
if err != nil {
4332
return err
4433
}
4534
diffCtx := formatter.Context{
46-
Output: dockerCli.Out(),
35+
Output: dockerCLI.Out(),
4736
Format: NewDiffFormat("{{.Type}} {{.Path}}"),
4837
}
4938
return DiffFormatWrite(diffCtx, changes)

cli/command/container/diff_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,3 @@ func TestRunDiffClientError(t *testing.T) {
7777
err := cmd.Execute()
7878
assert.ErrorIs(t, err, clientError)
7979
}
80-
81-
func TestRunDiffEmptyContainerError(t *testing.T) {
82-
cli := test.NewFakeCli(&fakeClient{})
83-
84-
cmd := NewDiffCommand(cli)
85-
cmd.SetOut(io.Discard)
86-
cmd.SetErr(io.Discard)
87-
88-
containerID := ""
89-
cmd.SetArgs([]string{containerID})
90-
91-
err := cmd.Execute()
92-
assert.Error(t, err, "Container name cannot be empty")
93-
}

0 commit comments

Comments
 (0)