From 86e79b55ed25facc7e76107f23d070a9957f6d41 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 20 Apr 2023 12:54:56 +0200 Subject: [PATCH] volumes: prune: add --all / -a option Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0dec5d20a239e22069dc82513404f6e3dd86a9ab) Signed-off-by: Sebastiaan van Stijn --- cli/command/volume/prune.go | 25 +++++- cli/command/volume/prune_test.go | 83 ++++++++++++++++--- .../volume/testdata/volume-prune-no.golden | 2 +- .../volume-prune-success.all-forced.golden | 1 + .../testdata/volume-prune-success.all.golden | 2 + .../volume-prune-success.label-filter.golden | 2 + .../volume/testdata/volume-prune-yes.golden | 2 +- contrib/completion/bash/docker | 2 +- contrib/completion/zsh/_docker | 2 + docs/reference/commandline/volume_prune.md | 18 ++-- 10 files changed, 117 insertions(+), 22 deletions(-) create mode 100644 cli/command/volume/testdata/volume-prune-success.all-forced.golden create mode 100644 cli/command/volume/testdata/volume-prune-success.all.golden create mode 100644 cli/command/volume/testdata/volume-prune-success.label-filter.golden diff --git a/cli/command/volume/prune.go b/cli/command/volume/prune.go index 16fd550898..e126f133b1 100644 --- a/cli/command/volume/prune.go +++ b/cli/command/volume/prune.go @@ -8,11 +8,15 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/opts" + "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/errdefs" units "github.com/docker/go-units" + "github.com/pkg/errors" "github.com/spf13/cobra" ) type pruneOptions struct { + all bool force bool filter opts.FilterOpt } @@ -41,18 +45,37 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() + flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused volumes, not just anonymous ones") + flags.SetAnnotation("all", "version", []string{"1.42"}) flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") flags.Var(&options.filter, "filter", `Provide filter values (e.g. "label=