Unexport system commands

This patch deprecates exported system commands and moves the
implementation details to an unexported function.

Commands that are affected include:

- system.NewVersionCommand
- system.NewInfoCommand
- system.NewSystemCommand
- system.NewEventsCommand
- system.NewInspectCommand

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
Alano Terblanche
2025-08-19 15:12:45 +02:00
parent 2e3d021912
commit cfb8cb91f2
10 changed files with 60 additions and 20 deletions

View File

@ -46,7 +46,9 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
registry.NewLoginCommand(dockerCli),
registry.NewLogoutCommand(dockerCli),
registry.NewSearchCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewVersionCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewInfoCommand(dockerCli),
// management commands
@ -64,6 +66,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
manifest.NewManifestCommand(dockerCli),
network.NewNetworkCommand(dockerCli),
plugin.NewPluginCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewSystemCommand(dockerCli),
trust.NewTrustCommand(dockerCli),
volume.NewVolumeCommand(dockerCli),
@ -130,7 +133,9 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
hide(image.NewSaveCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(image.NewTagCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(system.NewEventsCommand(dockerCli)),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
hide(system.NewInspectCommand(dockerCli)),
)
}

View File

@ -7,19 +7,26 @@ import (
)
// NewSystemCommand returns a cobra command for `system` subcommands
func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewSystemCommand(dockerCLI command.Cli) *cobra.Command {
return newSystemCommand(dockerCLI)
}
// newSystemCommand returns a cobra command for `system` subcommands
func newSystemCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "system",
Short: "Manage Docker",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
}
cmd.AddCommand(
NewEventsCommand(dockerCli),
NewInfoCommand(dockerCli),
newDiskUsageCommand(dockerCli),
newPruneCommand(dockerCli),
newDialStdioCommand(dockerCli),
newEventsCommand(dockerCLI),
newInfoCommand(dockerCLI),
newDiskUsageCommand(dockerCLI),
newPruneCommand(dockerCLI),
newDialStdioCommand(dockerCLI),
)
return cmd

View File

@ -156,7 +156,7 @@ func TestCompleteEventFilter(t *testing.T) {
for _, tc := range tests {
cli := test.NewFakeCli(tc.client)
completions, directive := completeEventFilters(cli)(NewEventsCommand(cli), nil, tc.toComplete)
completions, directive := completeEventFilters(cli)(newEventsCommand(cli), nil, tc.toComplete)
assert.DeepEqual(t, completions, tc.expected)
assert.Equal(t, directive, cobra.ShellCompDirectiveNoFileComp, fmt.Sprintf("wrong directive in completion for '%s'", tc.toComplete))

View File

@ -28,7 +28,14 @@ type eventsOptions struct {
}
// NewEventsCommand creates a new cobra.Command for `docker events`
func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewEventsCommand(dockerCLI command.Cli) *cobra.Command {
return newEventsCommand(dockerCLI)
}
// newEventsCommand creates a new cobra.Command for `docker events`
func newEventsCommand(dockerCLI command.Cli) *cobra.Command {
options := eventsOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -36,7 +43,7 @@ func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
Short: "Get real time events from the server",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runEvents(cmd.Context(), dockerCli, &options)
return runEvents(cmd.Context(), dockerCLI, &options)
},
Annotations: map[string]string{
"aliases": "docker system events, docker events",
@ -50,7 +57,7 @@ func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.StringVar(&options.format, "format", "", flagsHelper.InspectFormatHelp) // using the same flag description as "inspect" commands for now.
_ = cmd.RegisterFlagCompletionFunc("filter", completeEventFilters(dockerCli))
_ = cmd.RegisterFlagCompletionFunc("filter", completeEventFilters(dockerCLI))
return cmd
}

View File

@ -70,7 +70,7 @@ func TestEventsFormat(t *testing.T) {
}()
return messages, errs
}})
cmd := NewEventsCommand(cli)
cmd := newEventsCommand(cli)
cmd.SetArgs(tc.args)
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)

View File

@ -60,7 +60,14 @@ func (i *dockerInfo) clientPlatform() string {
}
// NewInfoCommand creates a new cobra.Command for `docker info`
func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewInfoCommand(dockerCLI command.Cli) *cobra.Command {
return newInfoCommand(dockerCLI)
}
// newInfoCommand creates a new cobra.Command for `docker info`
func newInfoCommand(dockerCLI command.Cli) *cobra.Command {
var opts infoOptions
cmd := &cobra.Command{
@ -68,7 +75,7 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
Short: "Display system-wide information",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runInfo(cmd.Context(), cmd, dockerCli, &opts)
return runInfo(cmd.Context(), cmd, dockerCLI, &opts)
},
Annotations: map[string]string{
"category-top": "12",

View File

@ -60,7 +60,14 @@ type inspectOptions struct {
}
// NewInspectCommand creates a new cobra.Command for `docker inspect`
func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewInspectCommand(dockerCLI command.Cli) *cobra.Command {
return newInspectCommand(dockerCLI)
}
// newInspectCommand creates a new cobra.Command for `docker inspect`
func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
var opts inspectOptions
cmd := &cobra.Command{
@ -72,7 +79,7 @@ func NewInspectCommand(dockerCli command.Cli) *cobra.Command {
if cmd.Flags().Changed("type") && opts.objectType == "" {
return fmt.Errorf(`type is empty: must be one of "%s"`, strings.Join(allTypes, `", "`))
}
return runInspect(cmd.Context(), dockerCli, opts)
return runInspect(cmd.Context(), dockerCLI, opts)
},
// TODO(thaJeztah): should we consider adding completion for common object-types? (images, containers?)
ValidArgsFunction: completion.NoComplete,

View File

@ -32,7 +32,7 @@ func TestInspectValidateFlagsAndArgs(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
cmd := NewInspectCommand(test.NewFakeCli(&fakeClient{}))
cmd := newInspectCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
cmd.SetArgs(tc.args)

View File

@ -109,7 +109,14 @@ func newClientVersion(contextName string, dockerCli command.Cli) clientVersion {
}
// NewVersionCommand creates a new cobra.Command for `docker version`
func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewVersionCommand(dockerCLI command.Cli) *cobra.Command {
return newVersionCommand(dockerCLI)
}
// newVersionCommand creates a new cobra.Command for `docker version`
func newVersionCommand(dockerCLI command.Cli) *cobra.Command {
var opts versionOptions
cmd := &cobra.Command{
@ -117,7 +124,7 @@ func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
Short: "Show the Docker version information",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runVersion(cmd.Context(), dockerCli, &opts)
return runVersion(cmd.Context(), dockerCLI, &opts)
},
Annotations: map[string]string{
"category-top": "10",

View File

@ -20,7 +20,7 @@ func TestVersionWithoutServer(t *testing.T) {
return types.Version{}, errors.New("no server")
},
})
cmd := NewVersionCommand(cli)
cmd := newVersionCommand(cli)
cmd.SetArgs([]string{})
cmd.SetOut(cli.Err())
cmd.SetErr(io.Discard)