summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_kill.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/pod_kill.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/pod_kill.go')
-rw-r--r--cmd/podman/pod_kill.go55
1 files changed, 27 insertions, 28 deletions
diff --git a/cmd/podman/pod_kill.go b/cmd/podman/pod_kill.go
index c8029eb46..43411a988 100644
--- a/cmd/podman/pod_kill.go
+++ b/cmd/podman/pod_kill.go
@@ -4,46 +4,45 @@ import (
"fmt"
"syscall"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/docker/docker/pkg/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- podKillFlags = []cli.Flag{
- cli.BoolFlag{
- Name: "all, a",
- Usage: "Kill all containers in all pods",
- },
- cli.StringFlag{
- Name: "signal, s",
- Usage: "Signal to send to the containers in the pod",
- Value: "KILL",
- },
- LatestPodFlag,
- }
+ podKillCommand cliconfig.PodKillValues
podKillDescription = "The main process of each container inside the specified pod will be sent SIGKILL, or any signal specified with option --signal."
- podKillCommand = cli.Command{
- Name: "kill",
- Usage: "Send the specified signal or SIGKILL to containers in pod",
- Description: podKillDescription,
- Flags: sortFlags(podKillFlags),
- Action: podKillCmd,
- ArgsUsage: "[POD_NAME_OR_ID]",
- UseShortOptionHandling: true,
- OnUsageError: usageErrorHandler,
+ _podKillCommand = &cobra.Command{
+ Use: "kill",
+ Short: "Send the specified signal or SIGKILL to containers in pod",
+ Long: podKillDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ podKillCommand.InputArgs = args
+ podKillCommand.GlobalFlags = MainGlobalOpts
+ return podKillCmd(&podKillCommand)
+ },
+ Example: "[POD_NAME_OR_ID]",
}
)
+func init() {
+ podKillCommand.Command = _podKillCommand
+ flags := podKillCommand.Flags()
+ flags.BoolVarP(&podKillCommand.All, "all", "a", false, "Kill all containers in all pods")
+ flags.BoolVarP(&podKillCommand.Latest, "latest", "l", false, "Act on the latest pod podman is aware of")
+ flags.StringVarP(&podKillCommand.Signal, "signal", "s", "KILL", "Signal to send to the containers in the pod")
+}
+
// podKillCmd kills one or more pods with a signal
-func podKillCmd(c *cli.Context) error {
- if err := checkMutuallyExclusiveFlags(c); err != nil {
+func podKillCmd(c *cliconfig.PodKillValues) error {
+ if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
return err
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@@ -51,10 +50,10 @@ func podKillCmd(c *cli.Context) error {
var killSignal uint = uint(syscall.SIGTERM)
- 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
}
@@ -64,7 +63,7 @@ func podKillCmd(c *cli.Context) error {
// getPodsFromContext returns an error when a requested pod
// isn't found. The only fatal error scenerio is when there are no pods
// in which case the following loop will be skipped.
- pods, lastError := getPodsFromContext(c, runtime)
+ pods, lastError := getPodsFromContext(&c.PodmanCommand, runtime)
for _, pod := range pods {
ctr_errs, err := pod.Kill(killSignal)