Merge pull request #6316 from Benehiko/command/network

Unexport network commands
This commit is contained in:
Sebastiaan van Stijn
2025-08-20 12:42:57 +02:00
committed by GitHub
4 changed files with 28 additions and 13 deletions
+1
View File
@@ -64,6 +64,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
image.NewImageCommand(dockerCli),
manifest.NewManifestCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
network.NewNetworkCommand(dockerCli),
plugin.NewPluginCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
+16 -9
View File
@@ -7,22 +7,29 @@ import (
)
// NewNetworkCommand returns a cobra command for `network` subcommands
func NewNetworkCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewNetworkCommand(dockerCLI command.Cli) *cobra.Command {
return newNetworkCommand(dockerCLI)
}
// newNetworkCommand returns a cobra command for `network` subcommands
func newNetworkCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "network",
Short: "Manage networks",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{"version": "1.21"},
}
cmd.AddCommand(
newConnectCommand(dockerCli),
newCreateCommand(dockerCli),
newDisconnectCommand(dockerCli),
newInspectCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
NewPruneCommand(dockerCli),
newConnectCommand(dockerCLI),
newCreateCommand(dockerCLI),
newDisconnectCommand(dockerCLI),
newInspectCommand(dockerCLI),
newListCommand(dockerCLI),
newRemoveCommand(dockerCLI),
newPruneCommand(dockerCLI),
)
return cmd
}
+10 -3
View File
@@ -26,7 +26,14 @@ type pruneOptions struct {
}
// NewPruneCommand returns a new cobra prune command for networks
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewPruneCommand(dockerCLI command.Cli) *cobra.Command {
return newPruneCommand(dockerCLI)
}
// newPruneCommand returns a new cobra prune command for networks
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@@ -34,12 +41,12 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
Short: "Remove all unused networks",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
output, err := runPrune(cmd.Context(), dockerCli, options)
output, err := runPrune(cmd.Context(), dockerCLI, options)
if err != nil {
return err
}
if output != "" {
_, _ = fmt.Fprintln(dockerCli.Out(), output)
_, _ = fmt.Fprintln(dockerCLI.Out(), output)
}
return nil
},
+1 -1
View File
@@ -20,7 +20,7 @@ func TestNetworkPrunePromptTermination(t *testing.T) {
return network.PruneReport{}, errors.New("fakeClient networkPruneFunc should not be called")
},
})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetArgs([]string{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)