Skip to content

Commit 9961e39

Browse files
committed
Unexport volume commands
This patch deprecates exported volume commands and moves the implementation details to an unexported function. Commands that are affected include: - volume.NewVolumeCommand - volume.NewPruneCommand Signed-off-by: Alano Terblanche <[email protected]>
1 parent 1d34432 commit 9961e39

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

cli/command/commands/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
7070
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
7171
system.NewSystemCommand(dockerCli),
7272
trust.NewTrustCommand(dockerCli),
73+
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
7374
volume.NewVolumeCommand(dockerCli),
7475

7576
// orchestration (swarm) commands

cli/command/volume/cmd.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ import (
77
)
88

99
// NewVolumeCommand returns a cobra command for `volume` subcommands
10-
func NewVolumeCommand(dockerCli command.Cli) *cobra.Command {
10+
//
11+
// Deprecated: Do not import commands directly. They will be removed in a future release.
12+
func NewVolumeCommand(dockerCLI command.Cli) *cobra.Command {
13+
return newVolumeCommand(dockerCLI)
14+
}
15+
16+
// newVolumeCommand returns a cobra command for `volume` subcommands
17+
func newVolumeCommand(dockerCLI command.Cli) *cobra.Command {
1118
cmd := &cobra.Command{
1219
Use: "volume COMMAND",
1320
Short: "Manage volumes",
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-
newCreateCommand(dockerCli),
20-
newInspectCommand(dockerCli),
21-
newListCommand(dockerCli),
22-
newRemoveCommand(dockerCli),
23-
NewPruneCommand(dockerCli),
24-
newUpdateCommand(dockerCli),
26+
newCreateCommand(dockerCLI),
27+
newInspectCommand(dockerCLI),
28+
newListCommand(dockerCLI),
29+
newRemoveCommand(dockerCLI),
30+
newPruneCommand(dockerCLI),
31+
newUpdateCommand(dockerCLI),
2532
)
2633
return cmd
2734
}

cli/command/volume/prune.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,29 @@ type pruneOptions struct {
3030
}
3131

3232
// NewPruneCommand returns a new cobra prune command for volumes
33-
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
33+
//
34+
// Deprecated: Do not import commands directly. They will be removed in a future release.
35+
func NewPruneCommand(dockerCLI command.Cli) *cobra.Command {
36+
return newPruneCommand(dockerCLI)
37+
}
38+
39+
// newPruneCommand returns a new cobra prune command for volumes
40+
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
3441
options := pruneOptions{filter: opts.NewFilterOpt()}
3542

3643
cmd := &cobra.Command{
3744
Use: "prune [OPTIONS]",
3845
Short: "Remove unused local volumes",
3946
Args: cli.NoArgs,
4047
RunE: func(cmd *cobra.Command, args []string) error {
41-
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCli, options)
48+
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCLI, options)
4249
if err != nil {
4350
return err
4451
}
4552
if output != "" {
46-
fmt.Fprintln(dockerCli.Out(), output)
53+
fmt.Fprintln(dockerCLI.Out(), output)
4754
}
48-
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
55+
fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
4956
return nil
5057
},
5158
Annotations: map[string]string{"version": "1.25"},

cli/command/volume/prune_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestVolumePruneErrors(t *testing.T) {
5353
}
5454
for _, tc := range testCases {
5555
t.Run(tc.name, func(t *testing.T) {
56-
cmd := NewPruneCommand(
56+
cmd := newPruneCommand(
5757
test.NewFakeCli(&fakeClient{
5858
volumePruneFunc: tc.volumePruneFunc,
5959
}),
@@ -105,7 +105,7 @@ func TestVolumePruneSuccess(t *testing.T) {
105105
for _, tc := range testCases {
106106
t.Run(tc.name, func(t *testing.T) {
107107
cli := test.NewFakeCli(&fakeClient{volumePruneFunc: tc.volumePruneFunc})
108-
cmd := NewPruneCommand(cli)
108+
cmd := newPruneCommand(cli)
109109
if tc.input != "" {
110110
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(tc.input))))
111111
}
@@ -135,7 +135,7 @@ func TestVolumePruneForce(t *testing.T) {
135135
cli := test.NewFakeCli(&fakeClient{
136136
volumePruneFunc: tc.volumePruneFunc,
137137
})
138-
cmd := NewPruneCommand(cli)
138+
cmd := newPruneCommand(cli)
139139
cmd.Flags().Set("force", "true")
140140
assert.NilError(t, cmd.Execute())
141141
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-prune.%s.golden", tc.name))
@@ -152,7 +152,7 @@ func TestVolumePrunePromptYes(t *testing.T) {
152152
})
153153

154154
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(input))))
155-
cmd := NewPruneCommand(cli)
155+
cmd := newPruneCommand(cli)
156156
cmd.SetArgs([]string{})
157157
assert.NilError(t, cmd.Execute())
158158
golden.Assert(t, cli.OutBuffer().String(), "volume-prune-yes.golden")
@@ -170,7 +170,7 @@ func TestVolumePrunePromptNo(t *testing.T) {
170170
})
171171

172172
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(input))))
173-
cmd := NewPruneCommand(cli)
173+
cmd := newPruneCommand(cli)
174174
cmd.SetArgs([]string{})
175175
cmd.SetOut(io.Discard)
176176
cmd.SetErr(io.Discard)
@@ -199,7 +199,7 @@ func TestVolumePrunePromptTerminate(t *testing.T) {
199199
},
200200
})
201201

202-
cmd := NewPruneCommand(cli)
202+
cmd := newPruneCommand(cli)
203203
cmd.SetArgs([]string{})
204204
cmd.SetOut(io.Discard)
205205
cmd.SetErr(io.Discard)

0 commit comments

Comments
 (0)