Skip to content

Commit ba8b22e

Browse files
BenehikothaJeztah
authored andcommitted
Unexport network commands
This patch deprecates exported network commands and moves the implementation details to an unexported function. Commands that are affected include: - network.NewNetworkCommand - network.NewPruneCommand Signed-off-by: Alano Terblanche <[email protected]> (cherry picked from commit 78a8856) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent def5bfc commit ba8b22e

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

cli/command/commands/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
6464
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6565
image.NewImageCommand(dockerCli),
6666
manifest.NewManifestCommand(dockerCli),
67+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
6768
network.NewNetworkCommand(dockerCli),
6869
plugin.NewPluginCommand(dockerCli),
6970
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)

cli/command/network/cmd.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@ import (
77
)
88

99
// NewNetworkCommand returns a cobra command for `network` subcommands
10-
func NewNetworkCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewNetworkCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newNetworkCommand(dockerCLI)
14+
}
15+
16+
// newNetworkCommand returns a cobra command for `network` subcommands
17+
func newNetworkCommand(dockerCLI command.Cli) *cobra.Command {
1118
cmd := &cobra.Command{
1219
Use: "network",
1320
Short: "Manage networks",
1421
Args: cli.NoArgs,
15-
RunE: command.ShowHelp(dockerCli.Err()),
22+
RunE: command.ShowHelp(dockerCLI.Err()),
1623
Annotations: map[string]string{"version": "1.21"},
1724
}
1825
cmd.AddCommand(
19-
newConnectCommand(dockerCli),
20-
newCreateCommand(dockerCli),
21-
newDisconnectCommand(dockerCli),
22-
newInspectCommand(dockerCli),
23-
newListCommand(dockerCli),
24-
newRemoveCommand(dockerCli),
25-
NewPruneCommand(dockerCli),
26+
newConnectCommand(dockerCLI),
27+
newCreateCommand(dockerCLI),
28+
newDisconnectCommand(dockerCLI),
29+
newInspectCommand(dockerCLI),
30+
newListCommand(dockerCLI),
31+
newRemoveCommand(dockerCLI),
32+
newPruneCommand(dockerCLI),
2633
)
2734
return cmd
2835
}

cli/command/network/prune.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@ type pruneOptions struct {
1818
}
1919

2020
// NewPruneCommand returns a new cobra prune command for networks
21-
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
21+
//
22+
// Deprecated: Do not import commands directly. They will be removed in a future release.
23+
func NewPruneCommand(dockerCLI command.Cli) *cobra.Command {
24+
return newPruneCommand(dockerCLI)
25+
}
26+
27+
// newPruneCommand returns a new cobra prune command for networks
28+
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
2229
options := pruneOptions{filter: opts.NewFilterOpt()}
2330

2431
cmd := &cobra.Command{
2532
Use: "prune [OPTIONS]",
2633
Short: "Remove all unused networks",
2734
Args: cli.NoArgs,
2835
RunE: func(cmd *cobra.Command, args []string) error {
29-
output, err := runPrune(cmd.Context(), dockerCli, options)
36+
output, err := runPrune(cmd.Context(), dockerCLI, options)
3037
if err != nil {
3138
return err
3239
}
3340
if output != "" {
34-
_, _ = fmt.Fprintln(dockerCli.Out(), output)
41+
_, _ = fmt.Fprintln(dockerCLI.Out(), output)
3542
}
3643
return nil
3744
},

cli/command/network/prune_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestNetworkPrunePromptTermination(t *testing.T) {
2020
return network.PruneReport{}, errors.New("fakeClient networkPruneFunc should not be called")
2121
},
2222
})
23-
cmd := NewPruneCommand(cli)
23+
cmd := newPruneCommand(cli)
2424
cmd.SetArgs([]string{})
2525
cmd.SetOut(io.Discard)
2626
cmd.SetErr(io.Discard)

0 commit comments

Comments
 (0)