newPruneCommand returns a new cobra prune command for images
(dockerCLI command.Cli)
| 32 | |
| 33 | // newPruneCommand returns a new cobra prune command for images |
| 34 | func 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 | |
| 65 | const ( |
| 66 | allImageWarning = `WARNING! This will remove all images without at least one container associated to them. |
searching dependent graphs…