feat: add short ID column to list, improve connect error with hint

This commit is contained in:
swanadiva
2026-06-23 14:23:11 +07:00
parent 1869cff590
commit 513492e6ee
2 changed files with 19 additions and 6 deletions
+13 -5
View File
@@ -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