Skip to content

Commit 9ca4ae9

Browse files
authored
Merge pull request #6305 from Benehiko/commands/system
Unexport system commands
2 parents 11a60e8 + cfb8cb9 commit 9ca4ae9

File tree

10 files changed

+60
-20
lines changed

10 files changed

+60
-20
lines changed

cli/command/commands/commands.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
4646
registry.NewLoginCommand(dockerCli),
4747
registry.NewLogoutCommand(dockerCli),
4848
registry.NewSearchCommand(dockerCli),
49+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
4950
system.NewVersionCommand(dockerCli),
51+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
5052
system.NewInfoCommand(dockerCli),
5153

5254
// management commands
@@ -64,6 +66,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
6466
manifest.NewManifestCommand(dockerCli),
6567
network.NewNetworkCommand(dockerCli),
6668
plugin.NewPluginCommand(dockerCli),
69+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6770
system.NewSystemCommand(dockerCli),
6871
trust.NewTrustCommand(dockerCli),
6972
volume.NewVolumeCommand(dockerCli),
@@ -130,7 +133,9 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
130133
hide(image.NewSaveCommand(dockerCli)),
131134
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
132135
hide(image.NewTagCommand(dockerCli)),
136+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
133137
hide(system.NewEventsCommand(dockerCli)),
138+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
134139
hide(system.NewInspectCommand(dockerCli)),
135140
)
136141
}

cli/command/system/cmd.go

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

99
// NewSystemCommand returns a cobra command for `system` subcommands
10-
func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewSystemCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newSystemCommand(dockerCLI)
14+
}
15+
16+
// newSystemCommand returns a cobra command for `system` subcommands
17+
func newSystemCommand(dockerCLI command.Cli) *cobra.Command {
1118
cmd := &cobra.Command{
1219
Use: "system",
1320
Short: "Manage Docker",
1421
Args: cli.NoArgs,
15-
RunE: command.ShowHelp(dockerCli.Err()),
22+
RunE: command.ShowHelp(dockerCLI.Err()),
1623
}
1724
cmd.AddCommand(
18-
NewEventsCommand(dockerCli),
19-
NewInfoCommand(dockerCli),
20-
newDiskUsageCommand(dockerCli),
21-
newPruneCommand(dockerCli),
22-
newDialStdioCommand(dockerCli),
25+
newEventsCommand(dockerCLI),
26+
newInfoCommand(dockerCLI),
27+
newDiskUsageCommand(dockerCLI),
28+
newPruneCommand(dockerCLI),
29+
newDialStdioCommand(dockerCLI),
2330
)
2431

2532
return cmd

cli/command/system/completion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func TestCompleteEventFilter(t *testing.T) {
156156
for _, tc := range tests {
157157
cli := test.NewFakeCli(tc.client)
158158

159-
completions, directive := completeEventFilters(cli)(NewEventsCommand(cli), nil, tc.toComplete)
159+
completions, directive := completeEventFilters(cli)(newEventsCommand(cli), nil, tc.toComplete)
160160

161161
assert.DeepEqual(t, completions, tc.expected)
162162
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp, fmt.Sprintf("wrong directive in completion for '%s'", tc.toComplete))

cli/command/system/events.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,22 @@ type eventsOptions struct {
2828
}
2929

3030
// NewEventsCommand creates a new cobra.Command for `docker events`
31-
func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
31+
//
32+
// Deprecated: Do not import commands directly. They will be removed in a future release.
33+
func NewEventsCommand(dockerCLI command.Cli) *cobra.Command {
34+
return newEventsCommand(dockerCLI)
35+
}
36+
37+
// newEventsCommand creates a new cobra.Command for `docker events`
38+
func newEventsCommand(dockerCLI command.Cli) *cobra.Command {
3239
options := eventsOptions{filter: opts.NewFilterOpt()}
3340

3441
cmd := &cobra.Command{
3542
Use: "events [OPTIONS]",
3643
Short: "Get real time events from the server",
3744
Args: cli.NoArgs,
3845
RunE: func(cmd *cobra.Command, args []string) error {
39-
return runEvents(cmd.Context(), dockerCli, &options)
46+
return runEvents(cmd.Context(), dockerCLI, &options)
4047
},
4148
Annotations: map[string]string{
4249
"aliases": "docker system events, docker events",
@@ -50,7 +57,7 @@ func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
5057
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
5158
flags.StringVar(&options.format, "format", "", flagsHelper.InspectFormatHelp) // using the same flag description as "inspect" commands for now.
5259

53-
_ = cmd.RegisterFlagCompletionFunc("filter", completeEventFilters(dockerCli))
60+
_ = cmd.RegisterFlagCompletionFunc("filter", completeEventFilters(dockerCLI))
5461

5562
return cmd
5663
}

cli/command/system/events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestEventsFormat(t *testing.T) {
7070
}()
7171
return messages, errs
7272
}})
73-
cmd := NewEventsCommand(cli)
73+
cmd := newEventsCommand(cli)
7474
cmd.SetArgs(tc.args)
7575
cmd.SetOut(io.Discard)
7676
cmd.SetErr(io.Discard)

cli/command/system/info.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,22 @@ func (i *dockerInfo) clientPlatform() string {
6060
}
6161

6262
// NewInfoCommand creates a new cobra.Command for `docker info`
63-
func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
63+
//
64+
// Deprecated: Do not import commands directly. They will be removed in a future release.
65+
func NewInfoCommand(dockerCLI command.Cli) *cobra.Command {
66+
return newInfoCommand(dockerCLI)
67+
}
68+
69+
// newInfoCommand creates a new cobra.Command for `docker info`
70+
func newInfoCommand(dockerCLI command.Cli) *cobra.Command {
6471
var opts infoOptions
6572

6673
cmd := &cobra.Command{
6774
Use: "info [OPTIONS]",
6875
Short: "Display system-wide information",
6976
Args: cli.NoArgs,
7077
RunE: func(cmd *cobra.Command, args []string) error {
71-
return runInfo(cmd.Context(), cmd, dockerCli, &opts)
78+
return runInfo(cmd.Context(), cmd, dockerCLI, &opts)
7279
},
7380
Annotations: map[string]string{
7481
"category-top": "12",

cli/command/system/inspect.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ type inspectOptions struct {
6060
}
6161

6262
// NewInspectCommand creates a new cobra.Command for `docker inspect`
63-
func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
63+
//
64+
// Deprecated: Do not import commands directly. They will be removed in a future release.
65+
func NewInspectCommand(dockerCLI command.Cli) *cobra.Command {
66+
return newInspectCommand(dockerCLI)
67+
}
68+
69+
// newInspectCommand creates a new cobra.Command for `docker inspect`
70+
func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
6471
var opts inspectOptions
6572

6673
cmd := &cobra.Command{
@@ -72,7 +79,7 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
7279
if cmd.Flags().Changed("type") && opts.objectType == "" {
7380
return fmt.Errorf(`type is empty: must be one of "%s"`, strings.Join(allTypes, `", "`))
7481
}
75-
return runInspect(cmd.Context(), dockerCli, opts)
82+
return runInspect(cmd.Context(), dockerCLI, opts)
7683
},
7784
// TODO(thaJeztah): should we consider adding completion for common object-types? (images, containers?)
7885
ValidArgsFunction: completion.NoComplete,

cli/command/system/inspect_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestInspectValidateFlagsAndArgs(t *testing.T) {
3232
},
3333
} {
3434
t.Run(tc.name, func(t *testing.T) {
35-
cmd := NewInspectCommand(test.NewFakeCli(&fakeClient{}))
35+
cmd := newInspectCommand(test.NewFakeCli(&fakeClient{}))
3636
cmd.SetOut(io.Discard)
3737
cmd.SetErr(io.Discard)
3838
cmd.SetArgs(tc.args)

cli/command/system/version.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,22 @@ func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
109109
}
110110

111111
// NewVersionCommand creates a new cobra.Command for `docker version`
112-
func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
112+
//
113+
// Deprecated: Do not import commands directly. They will be removed in a future release.
114+
func NewVersionCommand(dockerCLI command.Cli) *cobra.Command {
115+
return newVersionCommand(dockerCLI)
116+
}
117+
118+
// newVersionCommand creates a new cobra.Command for `docker version`
119+
func newVersionCommand(dockerCLI command.Cli) *cobra.Command {
113120
var opts versionOptions
114121

115122
cmd := &cobra.Command{
116123
Use: "version [OPTIONS]",
117124
Short: "Show the Docker version information",
118125
Args: cli.NoArgs,
119126
RunE: func(cmd *cobra.Command, args []string) error {
120-
return runVersion(cmd.Context(), dockerCli, &opts)
127+
return runVersion(cmd.Context(), dockerCLI, &opts)
121128
},
122129
Annotations: map[string]string{
123130
"category-top": "10",

cli/command/system/version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestVersionWithoutServer(t *testing.T) {
2020
return types.Version{}, errors.New("no server")
2121
},
2222
})
23-
cmd := NewVersionCommand(cli)
23+
cmd := newVersionCommand(cli)
2424
cmd.SetArgs([]string{})
2525
cmd.SetOut(cli.Err())
2626
cmd.SetErr(io.Discard)

0 commit comments

Comments
 (0)