feat: add short ID column to list, improve connect error with hint
This commit is contained in:
+13
-5
@@ -150,15 +150,23 @@ func sortHosts(hosts []*models.Host, sortBy string) {
|
||||
}
|
||||
}
|
||||
|
||||
func shortID(id string) string {
|
||||
if len(id) >= 8 {
|
||||
return id[:8]
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func outputTable(hosts []*models.Host) error {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
|
||||
fmt.Fprintln(w, "NAME\tHOSTNAME\tPORT\tUSER\tGROUP\tAUTH\tTAGS")
|
||||
fmt.Fprintln(w, "────\t────────\t────\t────\t─────\t────\t────")
|
||||
fmt.Fprintln(w, "ID\tNAME\tHOSTNAME\tPORT\tUSER\tGROUP\tAUTH\tTAGS")
|
||||
fmt.Fprintln(w, "--\t────\t────────\t────\t────\t─────\t────\t────")
|
||||
|
||||
for _, h := range hosts {
|
||||
tags := strings.Join(h.Tags, ", ")
|
||||
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\n",
|
||||
shortID(h.ID),
|
||||
h.Name,
|
||||
h.Hostname,
|
||||
h.Port,
|
||||
@@ -178,8 +186,8 @@ func outputJSON(hosts []*models.Host) error {
|
||||
if i > 0 {
|
||||
fmt.Print(",")
|
||||
}
|
||||
fmt.Printf(`{"id":"%s","name":"%s","hostname":"%s","port":%d,"username":"%s","group":"%s","auth_type":"%s"}`,
|
||||
h.ID, h.Name, h.Hostname, h.Port, h.Username, h.Group, h.Auth.Type)
|
||||
fmt.Printf(`{"id":"%s","short_id":"%s","name":"%s","hostname":"%s","port":%d,"username":"%s","group":"%s","auth_type":"%s"}`,
|
||||
h.ID, shortID(h.ID), h.Name, h.Hostname, h.Port, h.Username, h.Group, h.Auth.Type)
|
||||
}
|
||||
fmt.Println("]")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user