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 <18033717+Benehiko@users.noreply.github.com>
(cherry picked from commit 9961e39d40)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Alano Terblanche
2025-08-20 12:57:33 +02:00
committed by Sebastiaan van Stijn
parent 01ea3a7da7
commit 3e36fa624a
4 changed files with 33 additions and 18 deletions

View File

@ -71,6 +71,7 @@ func AddCommands(cmd *cobra.Command, dockerCli command.Cli) {
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
system.NewSystemCommand(dockerCli),
trust.NewTrustCommand(dockerCli),
//nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283)
volume.NewVolumeCommand(dockerCli),
// orchestration (swarm) commands

View File

@ -7,21 +7,28 @@ import (
)
// NewVolumeCommand returns a cobra command for `volume` subcommands
func NewVolumeCommand(dockerCli command.Cli) *cobra.Command {
//
// Deprecated: Do not import commands directly. They will be removed in a future release.
func NewVolumeCommand(dockerCLI command.Cli) *cobra.Command {
return newVolumeCommand(dockerCLI)
}
// newVolumeCommand returns a cobra command for `volume` subcommands
func newVolumeCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "volume COMMAND",
Short: "Manage volumes",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
RunE: command.ShowHelp(dockerCLI.Err()),
Annotations: map[string]string{"version": "1.21"},
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newInspectCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
NewPruneCommand(dockerCli),
newUpdateCommand(dockerCli),
newCreateCommand(dockerCLI),
newInspectCommand(dockerCLI),
newListCommand(dockerCLI),
newRemoveCommand(dockerCLI),
newPruneCommand(dockerCLI),
newUpdateCommand(dockerCLI),
)
return cmd
}

View File

@ -22,7 +22,14 @@ type pruneOptions struct {
}
// NewPruneCommand returns a new cobra prune command for volumes
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 volumes
func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
@ -30,14 +37,14 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
Short: "Remove unused local volumes",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCli, options)
spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCLI, options)
if err != nil {
return err
}
if output != "" {
fmt.Fprintln(dockerCli.Out(), output)
fmt.Fprintln(dockerCLI.Out(), output)
}
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
return nil
},
Annotations: map[string]string{"version": "1.25"},

View File

@ -53,7 +53,7 @@ func TestVolumePruneErrors(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmd := NewPruneCommand(
cmd := newPruneCommand(
test.NewFakeCli(&fakeClient{
volumePruneFunc: tc.volumePruneFunc,
}),
@ -105,7 +105,7 @@ func TestVolumePruneSuccess(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{volumePruneFunc: tc.volumePruneFunc})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
if tc.input != "" {
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(tc.input))))
}
@ -135,7 +135,7 @@ func TestVolumePruneForce(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
volumePruneFunc: tc.volumePruneFunc,
})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.Flags().Set("force", "true")
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-prune.%s.golden", tc.name))
@ -152,7 +152,7 @@ func TestVolumePrunePromptYes(t *testing.T) {
})
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(input))))
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetArgs([]string{})
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-prune-yes.golden")
@ -170,7 +170,7 @@ func TestVolumePrunePromptNo(t *testing.T) {
})
cli.SetIn(streams.NewIn(io.NopCloser(strings.NewReader(input))))
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetArgs([]string{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
@ -199,7 +199,7 @@ func TestVolumePrunePromptTerminate(t *testing.T) {
},
})
cmd := NewPruneCommand(cli)
cmd := newPruneCommand(cli)
cmd.SetArgs([]string{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)