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

Function newPruneCommand

cli/command/image/prune.go:34–63  ·  view source on GitHub ↗

newPruneCommand returns a new cobra prune command for images

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

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

Callers 4

newImageCommandFunction · 0.70

Calls 2

runPruneFunction · 0.70
OutMethod · 0.65

Tested by 3

Used in the wild real call sites across dependent graphs

searching dependent graphs…