aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/utils.go
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-07-25 17:31:21 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-27 12:39:12 +0000
commit876a30590b93757ca16ee607dee4f4458983620c (patch)
tree17d4127eb76af651d061507e7ecc8a3a6e77530f /cmd/podman/utils.go
parent3dd577e93c200e1af48cb8c08ac67962299c5d1f (diff)
downloadpodman-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/utils.go')
-rw-r--r--cmd/podman/utils.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 9d9e760d6..2d19e312c 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -174,3 +174,44 @@ func checkMutuallyExclusiveFlags(c *cli.Context) error {
}
return nil
}
+
+// For pod commands that have a latest and all flag, getPodsFromContext gets
+// pods the user specifies. If there's an error before getting pods, the pods slice
+// will be empty and error will be not nil. If an error occured after, the pod slice
+// will hold all of the successful pods, and error will hold the last error.
+// The remaining errors will be logged. On success, pods will hold all pods and
+// error will be nil.
+func getPodsFromContext(c *cli.Context, r *libpod.Runtime) ([]*libpod.Pod, error) {
+ args := c.Args()
+ var pods []*libpod.Pod
+ var lastError error
+ var err error
+
+ if c.Bool("all") {
+ pods, err = r.Pods()
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to get running pods")
+ }
+ }
+
+ if c.Bool("latest") {
+ pod, err := r.GetLatestPod()
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to get latest pod")
+ }
+ pods = append(pods, pod)
+ }
+
+ for _, i := range args {
+ pod, err := r.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)
+ }
+ return pods, lastError
+}