diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-08 20:12:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-08 20:12:38 +0100 |
commit | afd4d5f4a4b05f421e6f336b4d74a0d808be57ed (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/kill.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
parent | 25a3923b61a5ca014318e6d957f68abd03947297 (diff) | |
download | podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.gz podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.bz2 podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.zip |
Merge pull request #2274 from baude/cobraprep
Migrate to cobra CLI
Diffstat (limited to 'cmd/podman/kill.go')
-rw-r--r-- | cmd/podman/kill.go | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/cmd/podman/kill.go b/cmd/podman/kill.go index cfe4b4218..04c0fd531 100644 --- a/cmd/podman/kill.go +++ b/cmd/podman/kill.go @@ -4,6 +4,7 @@ import ( "fmt" "syscall" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" @@ -11,68 +12,66 @@ import ( "github.com/docker/docker/pkg/signal" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( - killFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Signal all running containers", - }, - cli.StringFlag{ - Name: "signal, s", - Usage: "Signal to send to the container", - Value: "KILL", - }, - LatestFlag, - } + killCommand cliconfig.KillValues + killDescription = "The main process inside each container specified will be sent SIGKILL, or any signal specified with option --signal." - killCommand = cli.Command{ - Name: "kill", - Usage: "Kill one or more running containers with a specific signal", - Description: killDescription, - Flags: sortFlags(killFlags), - Action: killCmd, - ArgsUsage: "CONTAINER-NAME [CONTAINER-NAME ...]", - UseShortOptionHandling: true, - OnUsageError: usageErrorHandler, + _killCommand = &cobra.Command{ + Use: "kill", + Short: "Kill one or more running containers with a specific signal", + Long: killDescription, + RunE: func(cmd *cobra.Command, args []string) error { + killCommand.InputArgs = args + killCommand.GlobalFlags = MainGlobalOpts + return killCmd(&killCommand) + }, + Example: "CONTAINER-NAME [CONTAINER-NAME ...]", } ) +func init() { + killCommand.Command = _killCommand + flags := killCommand.Flags() + + flags.BoolVarP(&killCommand.All, "all", "a", false, "Signal all running containers") + flags.StringVarP(&killCommand.Signal, "signal", "s", "KILL", "Signal to send to the container") + flags.BoolVarP(&killCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") + + rootCmd.AddCommand(killCommand.Command) +} + // killCmd kills one or more containers with a signal -func killCmd(c *cli.Context) error { +func killCmd(c *cliconfig.KillValues) error { var ( killFuncs []shared.ParallelWorkerInput killSignal uint = uint(syscall.SIGTERM) ) - if err := checkAllAndLatest(c); err != nil { - return err - } - - if err := validateFlags(c, killFlags); err != nil { + if err := checkAllAndLatest(&c.PodmanCommand); err != nil { return err } rootless.SetSkipStorageSetup(true) - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } defer runtime.Shutdown(false) - if c.String("signal") != "" { + if c.Signal != "" { // Check if the signalString provided by the user is valid // Invalid signals will return err - sysSignal, err := signal.ParseSignal(c.String("signal")) + sysSignal, err := signal.ParseSignal(c.Signal) if err != nil { return err } killSignal = uint(sysSignal) } - containers, err := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running") + containers, err := getAllOrLatestContainers(&c.PodmanCommand, runtime, libpod.ContainerStateRunning, "running") if err != nil { if len(containers) == 0 { return err @@ -94,7 +93,7 @@ func killCmd(c *cli.Context) error { maxWorkers := shared.Parallelize("kill") if c.GlobalIsSet("max-workers") { - maxWorkers = c.GlobalInt("max-workers") + maxWorkers = c.GlobalFlags.MaxWorks } logrus.Debugf("Setting maximum workers to %d", maxWorkers) |