pretty up ls members
Jes Olson j3s@c3f.net
Wed, 01 Mar 2023 20:52:58 -0800
1 files changed,
16 insertions(+),
13 deletions(-)
jump to
M
command/ls/members/members.go
→
command/ls/members/members.go
@@ -52,24 +52,27 @@ fmt.Println(err)
os.Exit(1) } - var b bytes.Buffer - tw := tabwriter.NewWriter(&b, 0, 2, 2, ' ', 0) if membersFlags.details { + var b bytes.Buffer + tw := tabwriter.NewWriter(&b, 0, 2, 2, ' ', 0) fmt.Fprintf(tw, "node\taddr\tstatus\ttags\n") - } - for _, m := range members { - if membersFlags.details { - fmt.Fprintf(tw, "%s\t%s:%d\t%s\t%v\n", m.Name, m.Addr, m.Port, m.StatusPretty(), printTags(m.Tags)) + for _, m := range members { + fmt.Fprintf(tw, "%s\t", m.Name) + fmt.Fprintf(tw, "%s:%d\t", m.Addr, m.Port) + fmt.Fprintf(tw, "%s\t", m.StatusPretty()) + fmt.Fprintf(tw, "%s\t", printTags(m.Tags)) + fmt.Fprintln(tw) + } + if err := tw.Flush(); err != nil { + fmt.Printf("error flushing tabwriter: %s", err) + os.Exit(1) } - if !membersFlags.details { - fmt.Fprintf(tw, "%s\n", m.Name) + fmt.Print(b.String()) + } else { + for _, m := range members { + fmt.Println(m.Name) } } - if err := tw.Flush(); err != nil { - fmt.Printf("error flushing tabwriter: %s", err) - os.Exit(1) - } - fmt.Print(b.String()) } func printTags(tags map[string]string) string {