未验证 提交 e2f5e059 编写于 作者: A Avi Aryan

show all fields in app command #60

上级 3aa77c1d
......@@ -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)
......
......@@ -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]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册