Skip to content

Commit e66a145

Browse files
committed
Unexport image commands
This patch deprecates exported image commands and moves the implementation details to an unexported function. Commands that are affected include: - image.NewBuildCommand - image.NewPullCommand - image.NewPushCommand - image.NewImagesCommand - image.NewImageCommand - image.NewHistoryCommand - image.NewImportCommand - image.NewLoadCommand - image.NewRemoveCommand - image.NewSaveCommand - image.NewTagCommand - image.NewPruneCommand Signed-off-by: Alano Terblanche <[email protected]>
1 parent fcb260d commit e66a145

24 files changed

+160
-62
lines changed

cli/command/builder/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func newBuilderCommand(dockerCLI command.Cli) *cobra.Command {
2525
}
2626
cmd.AddCommand(
2727
NewPruneCommand(dockerCLI),
28+
// we should have a mechanism for registering sub-commands in the cli/internal/commands.Register function.
29+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
2830
image.NewBuildCommand(dockerCLI),
2931
)
3032
return cmd

cli/command/commands/commands.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
3535
container.NewExecCommand(dockerCli),
3636
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3737
container.NewPsCommand(dockerCli),
38+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3839
image.NewBuildCommand(dockerCli),
40+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3941
image.NewPullCommand(dockerCli),
42+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4043
image.NewPushCommand(dockerCli),
44+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4145
image.NewImagesCommand(dockerCli),
4246
registry.NewLoginCommand(dockerCli),
4347
registry.NewLogoutCommand(dockerCli),
@@ -55,6 +59,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
5559
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5660
container.NewContainerCommand(dockerCli),
5761
context.NewContextCommand(dockerCli),
62+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5863
image.NewImageCommand(dockerCli),
5964
manifest.NewManifestCommand(dockerCli),
6065
network.NewNetworkCommand(dockerCli),
@@ -113,11 +118,17 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
113118
hide(container.NewUpdateCommand(dockerCli)),
114119
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
115120
hide(container.NewWaitCommand(dockerCli)),
121+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
116122
hide(image.NewHistoryCommand(dockerCli)),
123+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
117124
hide(image.NewImportCommand(dockerCli)),
125+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
118126
hide(image.NewLoadCommand(dockerCli)),
127+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
119128
hide(image.NewRemoveCommand(dockerCli)),
129+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
120130
hide(image.NewSaveCommand(dockerCli)),
131+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
121132
hide(image.NewTagCommand(dockerCli)),
122133
hide(system.NewEventsCommand(dockerCli)),
123134
hide(system.NewInspectCommand(dockerCli)),

cli/command/image/build.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ func newBuildOptions() buildOptions {
8181
}
8282

8383
// NewBuildCommand creates a new `docker build` command
84-
func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
84+
//
85+
// Deprecated: Do not import commands directly. They will be removed in a future release.
86+
func NewBuildCommand(dockerCLI command.Cli) *cobra.Command {
87+
return newBuildCommand(dockerCLI)
88+
}
89+
90+
// newBuildCommand creates a new `docker build` command
91+
func newBuildCommand(dockerCli command.Cli) *cobra.Command {
8592
options := newBuildOptions()
8693

8794
cmd := &cobra.Command{

cli/command/image/build_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ COPY data /data
120120
// to support testing (ex: docker/cli#294)
121121
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
122122
t.Setenv("DOCKER_BUILDKIT", "0")
123-
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
123+
cmd := newBuildCommand(test.NewFakeCli(&fakeClient{}))
124124
// Clone a small repo that exists so git doesn't prompt for credentials
125125
cmd.SetArgs([]string{"github.com/docker/for-win"})
126126
cmd.SetOut(io.Discard)
@@ -143,7 +143,7 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
143143
assert.NilError(t, err)
144144

145145
client := test.NewFakeCli(&fakeClient{})
146-
cmd := NewBuildCommand(client)
146+
cmd := newBuildCommand(client)
147147
cmd.SetArgs([]string{buildDir})
148148
cmd.SetOut(io.Discard)
149149
err = cmd.Execute()

cli/command/image/cmd.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@ import (
77
)
88

99
// NewImageCommand returns a cobra command for `image` subcommands
10-
func NewImageCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewImageCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newImageCommand(dockerCLI)
14+
}
15+
16+
// newImageCommand returns a cobra command for `image` subcommands
17+
func newImageCommand(dockerCli command.Cli) *cobra.Command {
1118
cmd := &cobra.Command{
1219
Use: "image",
1320
Short: "Manage images",
1421
Args: cli.NoArgs,
1522
RunE: command.ShowHelp(dockerCli.Err()),
1623
}
1724
cmd.AddCommand(
18-
NewBuildCommand(dockerCli),
19-
NewHistoryCommand(dockerCli),
20-
NewImportCommand(dockerCli),
21-
NewLoadCommand(dockerCli),
22-
NewPullCommand(dockerCli),
23-
NewPushCommand(dockerCli),
24-
NewSaveCommand(dockerCli),
25-
NewTagCommand(dockerCli),
25+
newBuildCommand(dockerCli),
26+
newHistoryCommand(dockerCli),
27+
newImportCommand(dockerCli),
28+
newLoadCommand(dockerCli),
29+
newPullCommand(dockerCli),
30+
newPushCommand(dockerCli),
31+
newSaveCommand(dockerCli),
32+
newTagCommand(dockerCli),
2633
newListCommand(dockerCli),
27-
newRemoveCommand(dockerCli),
34+
newImageRemoveCommand(dockerCli),
2835
newInspectCommand(dockerCli),
29-
NewPruneCommand(dockerCli),
36+
newPruneCommand(dockerCli),
3037
)
3138
return cmd
3239
}

cli/command/image/history.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ type historyOptions struct {
2525
}
2626

2727
// NewHistoryCommand creates a new `docker history` command
28-
func NewHistoryCommand(dockerCli command.Cli) *cobra.Command {
28+
//
29+
// Deprecated: Do not import commands directly. They will be removed in a future release.
30+
func NewHistoryCommand(dockerCLI command.Cli) *cobra.Command {
31+
return newHistoryCommand(dockerCLI)
32+
}
33+
34+
// newHistoryCommand creates a new `docker history` command
35+
func newHistoryCommand(dockerCLI command.Cli) *cobra.Command {
2936
var opts historyOptions
3037

3138
cmd := &cobra.Command{
@@ -34,9 +41,9 @@ func NewHistoryCommand(dockerCli command.Cli) *cobra.Command {
3441
Args: cli.ExactArgs(1),
3542
RunE: func(cmd *cobra.Command, args []string) error {
3643
opts.image = args[0]
37-
return runHistory(cmd.Context(), dockerCli, opts)
44+
return runHistory(cmd.Context(), dockerCLI, opts)
3845
},
39-
ValidArgsFunction: completion.ImageNames(dockerCli, 1),
46+
ValidArgsFunction: completion.ImageNames(dockerCLI, 1),
4047
Annotations: map[string]string{
4148
"aliases": "docker image history, docker history",
4249
},

cli/command/image/history_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
4242
}
4343
for _, tc := range testCases {
4444
t.Run(tc.name, func(t *testing.T) {
45-
cmd := NewHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
45+
cmd := newHistoryCommand(test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc}))
4646
cmd.SetOut(io.Discard)
4747
cmd.SetErr(io.Discard)
4848
cmd.SetArgs(tc.args)
@@ -114,7 +114,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
114114
// printed in the current timezone
115115
t.Setenv("TZ", "UTC")
116116
cli := test.NewFakeCli(&fakeClient{imageHistoryFunc: tc.imageHistoryFunc})
117-
cmd := NewHistoryCommand(cli)
117+
cmd := newHistoryCommand(cli)
118118
cmd.SetOut(io.Discard)
119119
cmd.SetArgs(tc.args)
120120
err := cmd.Execute()

cli/command/image/import.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ type importOptions struct {
2323
}
2424

2525
// NewImportCommand creates a new `docker import` command
26-
func NewImportCommand(dockerCli command.Cli) *cobra.Command {
26+
//
27+
// Deprecated: Do not import commands directly. They will be removed in a future release.
28+
func NewImportCommand(dockerCLI command.Cli) *cobra.Command {
29+
return newImportCommand(dockerCLI)
30+
}
31+
32+
// newImportCommand creates a new `docker import` command
33+
func newImportCommand(dockerCLI command.Cli) *cobra.Command {
2734
var options importOptions
2835

2936
cmd := &cobra.Command{
@@ -35,7 +42,7 @@ func NewImportCommand(dockerCli command.Cli) *cobra.Command {
3542
if len(args) > 1 {
3643
options.reference = args[1]
3744
}
38-
return runImport(cmd.Context(), dockerCli, options)
45+
return runImport(cmd.Context(), dockerCLI, options)
3946
},
4047
Annotations: map[string]string{
4148
"aliases": "docker image import, docker import",

cli/command/image/import_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestNewImportCommandErrors(t *testing.T) {
3434
},
3535
}
3636
for _, tc := range testCases {
37-
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
37+
cmd := newImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
3838
cmd.SetOut(io.Discard)
3939
cmd.SetErr(io.Discard)
4040
cmd.SetArgs(tc.args)
@@ -43,7 +43,7 @@ func TestNewImportCommandErrors(t *testing.T) {
4343
}
4444

4545
func TestNewImportCommandInvalidFile(t *testing.T) {
46-
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{}))
46+
cmd := newImportCommand(test.NewFakeCli(&fakeClient{}))
4747
cmd.SetOut(io.Discard)
4848
cmd.SetErr(io.Discard)
4949
cmd.SetArgs([]string{"testdata/import-command-success.unexistent-file"})
@@ -99,7 +99,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
9999
}
100100
for _, tc := range testCases {
101101
t.Run(tc.name, func(t *testing.T) {
102-
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
102+
cmd := newImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
103103
cmd.SetOut(io.Discard)
104104
cmd.SetErr(io.Discard)
105105
cmd.SetArgs(tc.args)

cli/command/image/list.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ type imagesOptions struct {
2929
}
3030

3131
// NewImagesCommand creates a new `docker images` command
32+
//
33+
// Deprecated: Do not import commands directly. They will be removed in a future release.
3234
func NewImagesCommand(dockerCLI command.Cli) *cobra.Command {
35+
return newImagesCommand(dockerCLI)
36+
}
37+
38+
// newImagesCommand creates a new `docker images` command
39+
func newImagesCommand(dockerCLI command.Cli) *cobra.Command {
3340
options := imagesOptions{filter: opts.NewFilterOpt()}
3441

3542
cmd := &cobra.Command{
@@ -69,7 +76,7 @@ func NewImagesCommand(dockerCLI command.Cli) *cobra.Command {
6976
}
7077

7178
func newListCommand(dockerCLI command.Cli) *cobra.Command {
72-
cmd := *NewImagesCommand(dockerCLI)
79+
cmd := *newImagesCommand(dockerCLI)
7380
cmd.Aliases = []string{"list"}
7481
cmd.Use = "ls [OPTIONS] [REPOSITORY[:TAG]]"
7582
return &cmd

0 commit comments

Comments
 (0)