summaryrefslogtreecommitdiff
path: root/cmd/podman/utils.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-08 02:02:30 -0700
committerGitHub <noreply@github.com>2019-04-08 02:02:30 -0700
commitd86729e743fb5a58b9364ee5e991b5db2e9dd600 (patch)
tree8ae6789a7e7e5e52de2270bb3854f01dc55b9949 /cmd/podman/utils.go
parentbc320be00bc584bd88525266d23a9d5edb9d44f8 (diff)
parent23602de816b9ee3e92a8cbac295e955ba43fa283 (diff)
downloadpodman-d86729e743fb5a58b9364ee5e991b5db2e9dd600.tar.gz
podman-d86729e743fb5a58b9364ee5e991b5db2e9dd600.tar.bz2
podman-d86729e743fb5a58b9364ee5e991b5db2e9dd600.zip
Merge pull request #2865 from baude/pr/2864
Revert "Switch to golangci-lint"
Diffstat (limited to 'cmd/podman/utils.go')
-rw-r--r--cmd/podman/utils.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 2327a943a..45d081512 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -7,6 +7,7 @@ import (
"os"
gosignal "os/signal"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/term"
@@ -158,6 +159,47 @@ func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return bytes, err
}
+// 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 *cliconfig.PodmanCommand, r *libpod.Runtime) ([]*libpod.Pod, error) {
+ args := c.InputArgs
+ var pods []*libpod.Pod
+ var lastError error
+ var err error
+
+ if c.Bool("all") {
+ pods, err = r.GetAllPods()
+ 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
+}
+
//printParallelOutput takes the map of parallel worker results and outputs them
// to stdout
func printParallelOutput(m map[string]error, errCount int) error {