Skip to content

Commit 85512e3

Browse files
authored
Merge pull request #6312 from thaJeztah/28.x_backport_deprecate_cobra_commands
[28.x backport] un-export and deprecate cobra commands
2 parents acb019a + ce242b0 commit 85512e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+797
-333
lines changed

cli/command/builder/cmd.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ import (
99
)
1010

1111
// NewBuilderCommand returns a cobra command for `builder` subcommands
12-
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
12+
//
13+
// Deprecated: Do not import commands directly. They will be removed in a future release.
14+
func NewBuilderCommand(dockerCLI command.Cli) *cobra.Command {
15+
return newBuilderCommand(dockerCLI)
16+
}
17+
18+
func newBuilderCommand(dockerCLI command.Cli) *cobra.Command {
1319
cmd := &cobra.Command{
1420
Use: "builder",
1521
Short: "Manage builds",
1622
Args: cli.NoArgs,
17-
RunE: command.ShowHelp(dockerCli.Err()),
23+
RunE: command.ShowHelp(dockerCLI.Err()),
1824
Annotations: map[string]string{"version": "1.31"},
1925
}
2026
cmd.AddCommand(
21-
NewPruneCommand(dockerCli),
22-
image.NewBuildCommand(dockerCli),
27+
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)
30+
image.NewBuildCommand(dockerCLI),
2331
)
2432
return cmd
2533
}
@@ -28,7 +36,13 @@ func NewBuilderCommand(dockerCli command.Cli) *cobra.Command {
2836
// This command is a placeholder / stub that is dynamically replaced by an
2937
// alias for "docker buildx bake" if BuildKit is enabled (and the buildx plugin
3038
// installed).
39+
//
40+
// Deprecated: Do not import commands directly. They will be removed in a future release.
3141
func NewBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
42+
return newBakeStubCommand(dockerCLI)
43+
}
44+
45+
func newBakeStubCommand(dockerCLI command.Streams) *cobra.Command {
3246
return &cobra.Command{
3347
Use: "bake [OPTIONS] [TARGET...]",
3448
Short: "Build from a file",

cli/command/checkpoint/cmd.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,28 @@ import (
77
)
88

99
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
10-
func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewCheckpointCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newCheckpointCommand(dockerCLI)
14+
}
15+
16+
func newCheckpointCommand(dockerCLI command.Cli) *cobra.Command {
1117
cmd := &cobra.Command{
1218
Use: "checkpoint",
1319
Short: "Manage checkpoints",
1420
Args: cli.NoArgs,
15-
RunE: command.ShowHelp(dockerCli.Err()),
21+
RunE: command.ShowHelp(dockerCLI.Err()),
1622
Annotations: map[string]string{
1723
"experimental": "",
1824
"ostype": "linux",
1925
"version": "1.25",
2026
},
2127
}
2228
cmd.AddCommand(
23-
newCreateCommand(dockerCli),
24-
newListCommand(dockerCli),
25-
newRemoveCommand(dockerCli),
29+
newCreateCommand(dockerCLI),
30+
newListCommand(dockerCLI),
31+
newRemoveCommand(dockerCLI),
2632
)
2733
return cmd
2834
}

cli/command/commands/commands.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,69 +29,127 @@ import (
2929
func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
3030
cmd.AddCommand(
3131
// commonly used shorthands
32+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3233
container.NewRunCommand(dockerCli),
34+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3335
container.NewExecCommand(dockerCli),
36+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3437
container.NewPsCommand(dockerCli),
38+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3539
image.NewBuildCommand(dockerCli),
40+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3641
image.NewPullCommand(dockerCli),
42+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3743
image.NewPushCommand(dockerCli),
44+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3845
image.NewImagesCommand(dockerCli),
46+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
3947
registry.NewLoginCommand(dockerCli),
48+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4049
registry.NewLogoutCommand(dockerCli),
50+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4151
registry.NewSearchCommand(dockerCli),
52+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4253
system.NewVersionCommand(dockerCli),
54+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4355
system.NewInfoCommand(dockerCli),
4456

4557
// management commands
58+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4659
builder.NewBakeStubCommand(dockerCli),
60+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4761
builder.NewBuilderCommand(dockerCli),
62+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4863
checkpoint.NewCheckpointCommand(dockerCli),
64+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4965
container.NewContainerCommand(dockerCli),
66+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5067
context.NewContextCommand(dockerCli),
68+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5169
image.NewImageCommand(dockerCli),
70+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5271
manifest.NewManifestCommand(dockerCli),
72+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5373
network.NewNetworkCommand(dockerCli),
74+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5475
plugin.NewPluginCommand(dockerCli),
76+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5577
system.NewSystemCommand(dockerCli),
78+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5679
trust.NewTrustCommand(dockerCli),
80+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5781
volume.NewVolumeCommand(dockerCli),
5882

5983
// orchestration (swarm) commands
84+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6085
config.NewConfigCommand(dockerCli),
86+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6187
node.NewNodeCommand(dockerCli),
88+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6289
secret.NewSecretCommand(dockerCli),
90+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6391
service.NewServiceCommand(dockerCli),
92+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6493
stack.NewStackCommand(dockerCli),
94+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6595
swarm.NewSwarmCommand(dockerCli),
6696

6797
// legacy commands may be hidden
98+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6899
hide(container.NewAttachCommand(dockerCli)),
100+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
69101
hide(container.NewCommitCommand(dockerCli)),
102+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
70103
hide(container.NewCopyCommand(dockerCli)),
104+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
71105
hide(container.NewCreateCommand(dockerCli)),
106+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
72107
hide(container.NewDiffCommand(dockerCli)),
108+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
73109
hide(container.NewExportCommand(dockerCli)),
110+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
74111
hide(container.NewKillCommand(dockerCli)),
112+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
75113
hide(container.NewLogsCommand(dockerCli)),
114+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
76115
hide(container.NewPauseCommand(dockerCli)),
116+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
77117
hide(container.NewPortCommand(dockerCli)),
118+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
78119
hide(container.NewRenameCommand(dockerCli)),
120+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
79121
hide(container.NewRestartCommand(dockerCli)),
122+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
80123
hide(container.NewRmCommand(dockerCli)),
124+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
81125
hide(container.NewStartCommand(dockerCli)),
126+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
82127
hide(container.NewStatsCommand(dockerCli)),
128+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
83129
hide(container.NewStopCommand(dockerCli)),
130+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
84131
hide(container.NewTopCommand(dockerCli)),
132+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
85133
hide(container.NewUnpauseCommand(dockerCli)),
134+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
86135
hide(container.NewUpdateCommand(dockerCli)),
136+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
87137
hide(container.NewWaitCommand(dockerCli)),
138+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
88139
hide(image.NewHistoryCommand(dockerCli)),
140+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
89141
hide(image.NewImportCommand(dockerCli)),
142+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
90143
hide(image.NewLoadCommand(dockerCli)),
144+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
91145
hide(image.NewRemoveCommand(dockerCli)),
146+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
92147
hide(image.NewSaveCommand(dockerCli)),
148+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
93149
hide(image.NewTagCommand(dockerCli)),
150+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
94151
hide(system.NewEventsCommand(dockerCli)),
152+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
95153
hide(system.NewInspectCommand(dockerCli)),
96154
)
97155
}

cli/command/config/cmd.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ import (
99
)
1010

1111
// NewConfigCommand returns a cobra command for `config` subcommands
12-
func NewConfigCommand(dockerCli command.Cli) *cobra.Command {
12+
//
13+
// Deprecated: Do not import commands directly. They will be removed in a future release.
14+
func NewConfigCommand(dockerCLI command.Cli) *cobra.Command {
15+
return newConfigCommand(dockerCLI)
16+
}
17+
18+
func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
1319
cmd := &cobra.Command{
1420
Use: "config",
1521
Short: "Manage Swarm configs",
1622
Args: cli.NoArgs,
17-
RunE: command.ShowHelp(dockerCli.Err()),
23+
RunE: command.ShowHelp(dockerCLI.Err()),
1824
Annotations: map[string]string{
1925
"version": "1.30",
2026
"swarm": "manager",
2127
},
2228
}
2329
cmd.AddCommand(
24-
newConfigListCommand(dockerCli),
25-
newConfigCreateCommand(dockerCli),
26-
newConfigInspectCommand(dockerCli),
27-
newConfigRemoveCommand(dockerCli),
30+
newConfigListCommand(dockerCLI),
31+
newConfigCreateCommand(dockerCLI),
32+
newConfigInspectCommand(dockerCLI),
33+
newConfigRemoveCommand(dockerCLI),
2834
)
2935
return cmd
3036
}

cli/command/container/attach.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClie
4141
}
4242

4343
// NewAttachCommand creates a new cobra.Command for `docker attach`
44+
//
45+
// Deprecated: Do not import commands directly. They will be removed in a future release.
4446
func NewAttachCommand(dockerCLI command.Cli) *cobra.Command {
47+
return newAttachCommand(dockerCLI)
48+
}
49+
50+
func newAttachCommand(dockerCLI command.Cli) *cobra.Command {
4551
var opts AttachOptions
4652

4753
cmd := &cobra.Command{

cli/command/container/attach_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
7474
}
7575
for _, tc := range testCases {
7676
t.Run(tc.name, func(t *testing.T) {
77-
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
77+
cmd := newAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
7878
cmd.SetOut(io.Discard)
7979
cmd.SetErr(io.Discard)
8080
cmd.SetArgs(tc.args)

cli/command/container/cmd.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,45 @@ import (
77
)
88

99
// NewContainerCommand returns a cobra command for `container` subcommands
10-
func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewContainerCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newContainerCommand(dockerCLI)
14+
}
15+
16+
func newContainerCommand(dockerCLI command.Cli) *cobra.Command {
1117
cmd := &cobra.Command{
1218
Use: "container",
1319
Short: "Manage containers",
1420
Args: cli.NoArgs,
15-
RunE: command.ShowHelp(dockerCli.Err()),
21+
RunE: command.ShowHelp(dockerCLI.Err()),
1622
}
1723
cmd.AddCommand(
18-
NewAttachCommand(dockerCli),
19-
NewCommitCommand(dockerCli),
20-
NewCopyCommand(dockerCli),
21-
NewCreateCommand(dockerCli),
22-
NewDiffCommand(dockerCli),
23-
NewExecCommand(dockerCli),
24-
NewExportCommand(dockerCli),
25-
NewKillCommand(dockerCli),
26-
NewLogsCommand(dockerCli),
27-
NewPauseCommand(dockerCli),
28-
NewPortCommand(dockerCli),
29-
NewRenameCommand(dockerCli),
30-
NewRestartCommand(dockerCli),
31-
newRemoveCommand(dockerCli),
32-
NewRunCommand(dockerCli),
33-
NewStartCommand(dockerCli),
34-
NewStatsCommand(dockerCli),
35-
NewStopCommand(dockerCli),
36-
NewTopCommand(dockerCli),
37-
NewUnpauseCommand(dockerCli),
38-
NewUpdateCommand(dockerCli),
39-
NewWaitCommand(dockerCli),
40-
newListCommand(dockerCli),
41-
newInspectCommand(dockerCli),
42-
NewPruneCommand(dockerCli),
24+
newAttachCommand(dockerCLI),
25+
newCommitCommand(dockerCLI),
26+
newCopyCommand(dockerCLI),
27+
newCreateCommand(dockerCLI),
28+
newDiffCommand(dockerCLI),
29+
newExecCommand(dockerCLI),
30+
newExportCommand(dockerCLI),
31+
newKillCommand(dockerCLI),
32+
newLogsCommand(dockerCLI),
33+
newPauseCommand(dockerCLI),
34+
newPortCommand(dockerCLI),
35+
newRenameCommand(dockerCLI),
36+
newRestartCommand(dockerCLI),
37+
newRemoveCommand(dockerCLI),
38+
newRunCommand(dockerCLI),
39+
newStartCommand(dockerCLI),
40+
newStatsCommand(dockerCLI),
41+
newStopCommand(dockerCLI),
42+
newTopCommand(dockerCLI),
43+
newUnpauseCommand(dockerCLI),
44+
newUpdateCommand(dockerCLI),
45+
newWaitCommand(dockerCLI),
46+
newListCommand(dockerCLI),
47+
newInspectCommand(dockerCLI),
48+
newPruneCommand(dockerCLI),
4349
)
4450
return cmd
4551
}

cli/command/container/commit.go

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

2525
// NewCommitCommand creates a new cobra.Command for `docker commit`
26-
func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
26+
//
27+
// Deprecated: Do not import commands directly. They will be removed in a future release.
28+
func NewCommitCommand(dockerCLI command.Cli) *cobra.Command {
29+
return newCommitCommand(dockerCLI)
30+
}
31+
32+
func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
2733
var options commitOptions
2834

2935
cmd := &cobra.Command{
@@ -35,12 +41,12 @@ func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
3541
if len(args) > 1 {
3642
options.reference = args[1]
3743
}
38-
return runCommit(cmd.Context(), dockerCli, &options)
44+
return runCommit(cmd.Context(), dockerCLI, &options)
3945
},
4046
Annotations: map[string]string{
4147
"aliases": "docker container commit, docker commit",
4248
},
43-
ValidArgsFunction: completion.ContainerNames(dockerCli, false),
49+
ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
4450
}
4551

4652
flags := cmd.Flags()

cli/command/container/commit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestRunCommit(t *testing.T) {
2929
},
3030
})
3131

32-
cmd := NewCommitCommand(cli)
32+
cmd := newCommitCommand(cli)
3333
cmd.SetOut(io.Discard)
3434
cmd.SetArgs(
3535
[]string{
@@ -60,7 +60,7 @@ func TestRunCommitClientError(t *testing.T) {
6060
},
6161
})
6262

63-
cmd := NewCommitCommand(cli)
63+
cmd := newCommitCommand(cli)
6464
cmd.SetOut(io.Discard)
6565
cmd.SetErr(io.Discard)
6666
cmd.SetArgs([]string{"container-id"})

cli/command/container/completion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestCompletePid(t *testing.T) {
5959
cli := test.NewFakeCli(&fakeClient{
6060
containerListFunc: tc.containerListFunc,
6161
})
62-
completions, directive := completePid(cli)(NewRunCommand(cli), nil, tc.toComplete)
62+
completions, directive := completePid(cli)(newRunCommand(cli), nil, tc.toComplete)
6363
assert.Check(t, is.DeepEqual(completions, tc.expectedCompletions))
6464
assert.Check(t, is.Equal(directive, tc.expectedDirective))
6565
})

0 commit comments

Comments
 (0)