newKillCommand creates a new cobra.Command for "docker container kill"
(dockerCLI command.Cli)
| 20 | |
| 21 | // newKillCommand creates a new cobra.Command for "docker container kill" |
| 22 | func newKillCommand(dockerCLI command.Cli) *cobra.Command { |
| 23 | var opts killOptions |
| 24 | |
| 25 | cmd := &cobra.Command{ |
| 26 | Use: "kill [OPTIONS] CONTAINER [CONTAINER...]", |
| 27 | Short: "Kill one or more running containers", |
| 28 | Args: cli.RequiresMinArgs(1), |
| 29 | RunE: func(cmd *cobra.Command, args []string) error { |
| 30 | opts.containers = args |
| 31 | return runKill(cmd.Context(), dockerCLI, &opts) |
| 32 | }, |
| 33 | Annotations: map[string]string{ |
| 34 | "aliases": "docker container kill, docker kill", |
| 35 | }, |
| 36 | ValidArgsFunction: completion.ContainerNames(dockerCLI, false), |
| 37 | DisableFlagsInUseLine: true, |
| 38 | } |
| 39 | |
| 40 | flags := cmd.Flags() |
| 41 | flags.StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container") |
| 42 | |
| 43 | _ = cmd.RegisterFlagCompletionFunc("signal", completeSignals) |
| 44 | |
| 45 | return cmd |
| 46 | } |
| 47 | |
| 48 | func runKill(ctx context.Context, dockerCLI command.Cli, opts *killOptions) error { |
| 49 | apiClient := dockerCLI.Client() |
searching dependent graphs…