MCPcopy Index your code
hub / github.com/docker/cli / newPruneCommand

Function newPruneCommand

cli/command/volume/prune.go:33–63  ·  view source on GitHub ↗

newPruneCommand returns a new cobra prune command for volumes

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

31
32// newPruneCommand returns a new cobra prune command for volumes
33func 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
65const (
66 unusedVolumesWarning = `WARNING! This will remove anonymous local volumes not used by at least one container.

Callers 7

TestVolumePruneErrorsFunction · 0.70
TestVolumePruneSuccessFunction · 0.70
TestVolumePruneForceFunction · 0.70
TestVolumePrunePromptYesFunction · 0.70
TestVolumePrunePromptNoFunction · 0.70
newVolumeCommandFunction · 0.70

Calls 2

runPruneFunction · 0.70
OutMethod · 0.65

Tested by 6

TestVolumePruneErrorsFunction · 0.56
TestVolumePruneSuccessFunction · 0.56
TestVolumePruneForceFunction · 0.56
TestVolumePrunePromptYesFunction · 0.56
TestVolumePrunePromptNoFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…