From e2f5e0598923724b043f09af9172a6afc4dbd99f Mon Sep 17 00:00:00 2001 From: Avi Aryan Date: Wed, 19 Jul 2017 13:04:20 +0530 Subject: [PATCH] show all fields in app command #60 --- appbase/app/app.go | 17 +++++++++++++++-- appbase/common/utils.go | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/appbase/app/app.go b/appbase/app/app.go index 4d93672..72f41d5 100644 --- a/appbase/app/app.go +++ b/appbase/app/app.go @@ -12,6 +12,7 @@ import ( "net/http" "os" "strconv" + "time" ) type appBody struct { @@ -26,8 +27,11 @@ type respBody struct { } type appDetailBody struct { - AppName string `json:"appname"` - ESVersion string `json:"es_version"` + AppName string `json:"appname"` + ESVersion string `json:"es_version"` + Owner string `json:"owner"` + Users []string `json:"users"` + CreatedAt time.Time `json:"created_at, string"` } type appRespBody struct { @@ -100,10 +104,19 @@ func ShowAppDetails(app string, perms bool, metrics bool) error { if err != nil { return err } + // prepare output + common.RemoveDuplicates(&res.Body.Users) + users := "" + for _, user := range res.Body.Users { + users += user + ", " + } // output fmt.Printf("ID: %s\n", app) fmt.Printf("Name: %s\n", res.Body.AppName) + fmt.Printf("Owner: %s\n", res.Body.Owner) + fmt.Printf("Users: %s\n", users[:len(users)-2]) fmt.Printf("ES Version: %s\n", res.Body.ESVersion) + fmt.Printf("Created on: %s\n", res.Body.CreatedAt.Format("Mon Jan _2 15:04:05 2006")) if perms { err = ShowAppPerms(app) diff --git a/appbase/common/utils.go b/appbase/common/utils.go index 60298ad..23d715e 100644 --- a/appbase/common/utils.go +++ b/appbase/common/utils.go @@ -91,3 +91,18 @@ func IsFileValid(file string) error { } return nil } + +// RemoveDuplicates removes duplicate values in a slice +// https://groups.google.com/forum/#!topic/golang-nuts/-pqkICuokio +func RemoveDuplicates(xs *[]string) { + found := make(map[string]bool) + j := 0 + for i, x := range *xs { + if !found[x] { + found[x] = true + (*xs)[j] = (*xs)[i] + j++ + } + } + *xs = (*xs)[:j] +} -- GitLab