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

Function newRmCommand

cli/command/container/rm.go:27–61  ·  view source on GitHub ↗

newRmCommand creates a new cobra.Command for "docker container rm".

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

25
26// newRmCommand creates a new cobra.Command for "docker container rm".
27func newRmCommand(dockerCLI command.Cli) *cobra.Command {
28 var opts rmOptions
29
30 completeLinkNames := completeLinks(dockerCLI)
31 completeNames := completion.ContainerNames(dockerCLI, true, func(ctr container.Summary) bool {
32 return opts.force || ctr.State == container.StateExited || ctr.State == container.StateCreated
33 })
34
35 cmd := &cobra.Command{
36 Use: "rm [OPTIONS] CONTAINER [CONTAINER...]",
37 Short: "Remove one or more containers",
38 Args: cli.RequiresMinArgs(1),
39 RunE: func(cmd *cobra.Command, args []string) error {
40 opts.containers = args
41 return runRm(cmd.Context(), dockerCLI, &opts)
42 },
43 Annotations: map[string]string{
44 "aliases": "docker container rm, docker container remove, docker rm",
45 },
46 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
47 if opts.rmLink {
48 // "--link" (remove link) is set; provide link names instead of container (primary) names.
49 return completeLinkNames(cmd, args, toComplete)
50 }
51 return completeNames(cmd, args, toComplete)
52 },
53 DisableFlagsInUseLine: true,
54 }
55
56 flags := cmd.Flags()
57 flags.BoolVarP(&opts.rmVolumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
58 flags.BoolVarP(&opts.rmLink, "link", "l", false, "Remove the specified link")
59 flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of a running container (uses SIGKILL)")
60 return cmd
61}
62
63// newRemoveCommand adds subcommands for "docker container"; unlike the
64// top-level "docker rm", it also adds a "remove" alias to support

Callers 2

TestRemoveForceFunction · 0.85
newRemoveCommandFunction · 0.85

Calls 3

completeLinksFunction · 0.85
runRmFunction · 0.85
completeNamesFunction · 0.50

Tested by 1

TestRemoveForceFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…