From 1415080cfaa2ba8f2ead3f56d29e9cb8f30095fd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 22 Aug 2025 12:18:27 +0200 Subject: [PATCH] cli/command/builder: deprecate NewPruneCommand This patch deprecates exported NewPruneCommand and moves the implementation details to an unexported function. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 7032f5922e4f49648b684b97b700c527fbcd3edf) Signed-off-by: Sebastiaan van Stijn --- cli/command/builder/cmd.go | 2 +- cli/command/builder/prune.go | 13 ++++++++++--- cli/command/builder/prune_test.go | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/command/builder/cmd.go b/cli/command/builder/cmd.go index 44d6496397ae..e65bdd3d394b 100644 --- a/cli/command/builder/cmd.go +++ b/cli/command/builder/cmd.go @@ -24,7 +24,7 @@ func newBuilderCommand(dockerCLI command.Cli) *cobra.Command { Annotations: map[string]string{"version": "1.31"}, } cmd.AddCommand( - NewPruneCommand(dockerCLI), + newPruneCommand(dockerCLI), // we should have a mechanism for registering sub-commands in the cli/internal/commands.Register function. //nolint:staticcheck // TODO: Remove when migration to cli/internal/commands.Register is complete. (see #6283) image.NewBuildCommand(dockerCLI), diff --git a/cli/command/builder/prune.go b/cli/command/builder/prune.go index 7a323a393941..1c36f358edfa 100644 --- a/cli/command/builder/prune.go +++ b/cli/command/builder/prune.go @@ -24,7 +24,14 @@ type pruneOptions struct { } // NewPruneCommand returns a new cobra prune command for images +// +// 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 images +func newPruneCommand(dockerCLI command.Cli) *cobra.Command { options := pruneOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ @@ -32,14 +39,14 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command { Short: "Remove build cache", 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.39"}, diff --git a/cli/command/builder/prune_test.go b/cli/command/builder/prune_test.go index e0c3097b07e2..de1582cf6a77 100644 --- a/cli/command/builder/prune_test.go +++ b/cli/command/builder/prune_test.go @@ -19,7 +19,7 @@ func TestBuilderPromptTermination(t *testing.T) { return nil, errors.New("fakeClient builderPruneFunc should not be called") }, }) - cmd := NewPruneCommand(cli) + cmd := newPruneCommand(cli) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) test.TerminatePrompt(ctx, t, cmd, cli)