From c10ac01395066ddeb321a83ab64bc02b2e765f9a Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Tue, 16 Oct 2018 16:39:11 +0000 Subject: Use the newly added getAllOrLatestContainers() function This removes duplicate code paths which has been previously factored out as getAllOrLatestContainers(). Signed-off-by: Adrian Reber --- cmd/podman/stop.go | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'cmd/podman/stop.go') diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go index f5c0fca85..edadbda89 100644 --- a/cmd/podman/stop.go +++ b/cmd/podman/stop.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "os" rt "runtime" "github.com/containers/libpod/cmd/podman/libpodruntime" @@ -60,40 +59,7 @@ func stopCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - 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 { - args := c.Args() - 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") var stopFuncs []workerInput for _, ctr := range containers { -- cgit v1.2.3-54-g00ecf