newPruneCommand creates a new cobra.Command for `docker prune`
(dockerCLI command.Cli)
| 31 | |
| 32 | // newPruneCommand creates a new cobra.Command for `docker prune` |
| 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 data", |
| 39 | Args: cli.NoArgs, |
| 40 | RunE: func(cmd *cobra.Command, args []string) error { |
| 41 | return runPrune(cmd.Context(), dockerCLI, options) |
| 42 | }, |
| 43 | Annotations: map[string]string{"version": "1.25"}, |
| 44 | ValidArgsFunction: cobra.NoFileCompletions, |
| 45 | DisableFlagsInUseLine: true, |
| 46 | } |
| 47 | |
| 48 | flags := cmd.Flags() |
| 49 | flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") |
| 50 | flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones") |
| 51 | flags.BoolVar(&options.pruneVolumes, "volumes", false, "Prune anonymous volumes") |
| 52 | flags.Var(&options.filter, "filter", `Provide filter values (e.g. "label=<key>=<value>")`) |
| 53 | // "filter" flag is available in 1.28 (docker 17.04) and up |
| 54 | flags.SetAnnotation("filter", "version", []string{"1.28"}) |
| 55 | |
| 56 | return cmd |
| 57 | } |
| 58 | |
| 59 | const confirmationTemplate = `WARNING! This will remove: |
| 60 | {{- range $_, $warning := .warnings }} |
searching dependent graphs…