newPruneCommand returns a new cobra prune command for volumes
(dockerCLI command.Cli)
| 31 | |
| 32 | // newPruneCommand returns a new cobra prune command for volumes |
| 33 | func newPruneCommand(dockerCLI command.Cli) *cobra.Command { |
| 34 | options := pruneOptions{filter: opts.NewFilterOpt()} |
| 35 | |
| 36 | cmd := &cobra.Command{ |
| 37 | Use: "prune [OPTIONS]", |
| 38 | Short: "Remove unused local volumes", |
| 39 | Args: cli.NoArgs, |
| 40 | RunE: func(cmd *cobra.Command, args []string) error { |
| 41 | spaceReclaimed, output, err := runPrune(cmd.Context(), dockerCLI, options) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | if output != "" { |
| 46 | fmt.Fprintln(dockerCLI.Out(), output) |
| 47 | } |
| 48 | fmt.Fprintln(dockerCLI.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) |
| 49 | return nil |
| 50 | }, |
| 51 | Annotations: map[string]string{"version": "1.25"}, |
| 52 | ValidArgsFunction: cobra.NoFileCompletions, |
| 53 | DisableFlagsInUseLine: true, |
| 54 | } |
| 55 | |
| 56 | flags := cmd.Flags() |
| 57 | flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused volumes, not just anonymous ones") |
| 58 | flags.SetAnnotation("all", "version", []string{"1.42"}) |
| 59 | flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") |
| 60 | flags.Var(&options.filter, "filter", `Provide filter values (e.g. "label=<label>")`) |
| 61 | |
| 62 | return cmd |
| 63 | } |
| 64 | |
| 65 | const ( |
| 66 | unusedVolumesWarning = `WARNING! This will remove anonymous local volumes not used by at least one container. |
searching dependent graphs…