summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-12-13 11:23:01 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-14 14:14:34 +0000
commitd8f099bb5a38b85bdea2bf6d99e0dbd0457ab666 (patch)
treee4056e7a08729ee82d4e01e169ee4706d1f5f5c7 /cmd
parent05f4dd9f41707959ce801f9851c79232a1b79dca (diff)
downloadpodman-d8f099bb5a38b85bdea2bf6d99e0dbd0457ab666.tar.gz
podman-d8f099bb5a38b85bdea2bf6d99e0dbd0457ab666.tar.bz2
podman-d8f099bb5a38b85bdea2bf6d99e0dbd0457ab666.zip
Check for mutually exclusive flags
Error out if more than one mutually exclusive flags are passed in to kpod ps Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #128 Approved by: rhatdan
Diffstat (limited to 'cmd')
-rw-r--r--cmd/kpod/ps.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/cmd/kpod/ps.go b/cmd/kpod/ps.go
index 4148edf68..89fed991f 100644
--- a/cmd/kpod/ps.go
+++ b/cmd/kpod/ps.go
@@ -143,9 +143,8 @@ func psCmd(c *cli.Context) error {
return err
}
- // latest, and last are mutually exclusive.
- if c.Int("last") >= 0 && c.Bool("latest") {
- return errors.Errorf("last and latest are mutually exclusive")
+ if err := checkFlagsPassed(c); err != nil {
+ return errors.Wrapf(err, "error with flags passed")
}
runtime, err := getRuntime(c)
@@ -212,6 +211,32 @@ func psCmd(c *cli.Context) error {
return generatePsOutput(outputContainers, opts)
}
+// checkFlagsPassed checks if mutually exclusive flags are passed together
+func checkFlagsPassed(c *cli.Context) error {
+ // latest, and last are mutually exclusive.
+ if c.Int("last") >= 0 && c.Bool("latest") {
+ return errors.Errorf("last and latest are mutually exclusive")
+ }
+ // quiet, size, namespace, and format with Go template are mutually exclusive
+ flags := 0
+ if c.Bool("quiet") {
+ flags++
+ }
+ if c.Bool("size") {
+ flags++
+ }
+ if c.Bool("namespace") {
+ flags++
+ }
+ if c.IsSet("format") && c.String("format") != formats.JSONString {
+ flags++
+ }
+ if flags > 1 {
+ return errors.Errorf("quiet, size, namespace, and format with Go template are mutually exclusive")
+ }
+ return nil
+}
+
func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Runtime) (func(container *libpod.Container) bool, error) {
switch filter {
case "id":