summaryrefslogtreecommitdiff
path: root/cmd/podman/kill.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/kill.go')
-rw-r--r--cmd/podman/kill.go48
1 files changed, 4 insertions, 44 deletions
diff --git a/cmd/podman/kill.go b/cmd/podman/kill.go
index 56dd170b5..7ca5bd7c5 100644
--- a/cmd/podman/kill.go
+++ b/cmd/podman/kill.go
@@ -41,19 +41,10 @@ var (
// killCmd kills one or more containers with a signal
func killCmd(c *cli.Context) error {
- args := c.Args()
- if (!c.Bool("all") && !c.Bool("latest")) && len(args) == 0 {
- return errors.Errorf("you must specify one or more containers to kill")
- }
- if (c.Bool("all") || c.Bool("latest")) && len(args) > 0 {
- return errors.Errorf("you cannot specify any containers to kill with --latest or --all")
- }
- if c.Bool("all") && c.Bool("latest") {
- return errors.Errorf("--all and --latest cannot be used together")
- }
- if len(args) < 1 && !c.Bool("all") && !c.Bool("latest") {
- return errors.Errorf("you must provide at least one container name or id")
+ if err := checkAllAndLatest(c); err != nil {
+ return err
}
+
if err := validateFlags(c, killFlags); err != nil {
return err
}
@@ -76,38 +67,7 @@ func killCmd(c *cli.Context) error {
killSignal = uint(sysSignal)
}
- var filterFuncs []libpod.ContainerFilter
- var containers []*libpod.Container
- var lastError error
- if c.Bool("all") {
- // only get running containers
- filterFuncs = append(filterFuncs, func(c *libpod.Container) bool {
- state, _ := c.State()
- return state == libpod.ContainerStateRunning
- })
- containers, err = runtime.GetContainers(filterFuncs...)
- if err != nil {
- return errors.Wrapf(err, "unable to get running containers")
- }
- } else if c.Bool("latest") {
- lastCtr, err := runtime.GetLatestContainer()
- if err != nil {
- return errors.Wrapf(err, "unable to get last created container")
- }
- containers = append(containers, lastCtr)
- } else {
- for _, i := range args {
- container, err := runtime.LookupContainer(i)
- if err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "unable to find container %s", i)
- continue
- }
- containers = append(containers, container)
- }
- }
+ containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
for _, ctr := range containers {
if err := ctr.Kill(killSignal); err != nil {