diff options
author | haircommander <pehunt@redhat.com> | 2018-07-25 17:31:21 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-07-27 12:39:12 +0000 |
commit | 876a30590b93757ca16ee607dee4f4458983620c (patch) | |
tree | 17d4127eb76af651d061507e7ecc8a3a6e77530f /cmd/podman/pod_stop.go | |
parent | 3dd577e93c200e1af48cb8c08ac67962299c5d1f (diff) | |
download | podman-876a30590b93757ca16ee607dee4f4458983620c.tar.gz podman-876a30590b93757ca16ee607dee4f4458983620c.tar.bz2 podman-876a30590b93757ca16ee607dee4f4458983620c.zip |
Refactored method of getting pods
Now, for commands that have --latest and --all, the context flags are checked, and pods are grabbed in a single function
Signed-off-by: haircommander <pehunt@redhat.com>
Closes: #1161
Approved by: rhatdan
Diffstat (limited to 'cmd/podman/pod_stop.go')
-rw-r--r-- | cmd/podman/pod_stop.go | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/cmd/podman/pod_stop.go b/cmd/podman/pod_stop.go index 85904ebf3..97d248b30 100644 --- a/cmd/podman/pod_stop.go +++ b/cmd/podman/pod_stop.go @@ -5,7 +5,6 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" - "github.com/projectatomic/libpod/libpod" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -45,36 +44,10 @@ func podStopCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - args := c.Args() - var pods []*libpod.Pod - var lastError error - - if c.Bool("all") { - pods, err = runtime.Pods() - if err != nil { - return errors.Wrapf(err, "unable to get running pods") - } - } - - if c.Bool("latest") { - pod, err := runtime.GetLatestPod() - if err != nil { - return errors.Wrapf(err, "unable to get latest pod") - } - pods = append(pods, pod) - } - - for _, i := range args { - pod, err := runtime.LookupPod(i) - if err != nil { - if lastError != nil { - logrus.Errorf("%q", lastError) - } - lastError = errors.Wrapf(err, "unable to find pod %s", i) - continue - } - pods = append(pods, pod) - } + // 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) for _, pod := range pods { // set cleanup to true to clean mounts and namespaces |