newRemoveCommand creates a new "docker image remove" command
(dockerCLI command.Cli)
| 22 | |
| 23 | // newRemoveCommand creates a new "docker image remove" command |
| 24 | func newRemoveCommand(dockerCLI command.Cli) *cobra.Command { |
| 25 | var options removeOptions |
| 26 | |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "rmi [OPTIONS] IMAGE [IMAGE...]", |
| 29 | Short: "Remove one or more images", |
| 30 | Args: cli.RequiresMinArgs(1), |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | return runRemove(cmd.Context(), dockerCLI, options, args) |
| 33 | }, |
| 34 | ValidArgsFunction: completion.ImageNames(dockerCLI, -1), |
| 35 | Annotations: map[string]string{ |
| 36 | "aliases": "docker image rm, docker image remove, docker rmi", |
| 37 | }, |
| 38 | DisableFlagsInUseLine: true, |
| 39 | } |
| 40 | |
| 41 | flags := cmd.Flags() |
| 42 | |
| 43 | flags.BoolVarP(&options.force, "force", "f", false, "Force removal of the image") |
| 44 | flags.BoolVar(&options.noPrune, "no-prune", false, "Do not delete untagged parents") |
| 45 | |
| 46 | // TODO(thaJeztah): create a "platforms" option for this (including validation / parsing). |
| 47 | flags.StringSliceVar(&options.platforms, "platform", nil, `Remove only the given platform variant. Formatted as "os[/arch[/variant]]" (e.g., "linux/amd64")`) |
| 48 | _ = flags.SetAnnotation("platform", "version", []string{"1.50"}) |
| 49 | |
| 50 | _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) |
| 51 | return cmd |
| 52 | } |
| 53 | |
| 54 | // newImageRemoveCommand is a sub-command under `image` (`docker image rm`) |
| 55 | func newImageRemoveCommand(dockerCli command.Cli) *cobra.Command { |
searching dependent graphs…