1515package cmd
1616
1717import (
18+ "fmt"
19+ "os"
1820 "strings"
1921
2022 "github.com/humio/cli/api"
23+ "github.com/olekukonko/tablewriter"
2124 "github.com/spf13/cobra"
2225)
2326
@@ -42,10 +45,32 @@ func formatSimpleAccount(account api.User) string {
4245}
4346
4447func printUserTable (user api.User ) {
45- userData := []string {user .Username , user .FullName , user .CreatedAt , yesNo (user .IsRoot )}
4648
47- printTable ([]string {
48- "Username | Name | Created At | Is Root" ,
49- strings .Join (userData , "|" ),
50- })
49+ data := [][]string {
50+ []string {"Username" , user .Username },
51+ []string {"Name" , user .FullName },
52+ []string {"Is Root" , yesNo (user .IsRoot )},
53+ []string {"Roles" , strings .Join (userRoleNames (user ), ", " )},
54+ []string {"Created At" , user .CreatedAt },
55+ []string {"Country Code" , user .CountryCode },
56+ []string {"Company" , user .Company },
57+ }
58+
59+ w := tablewriter .NewWriter (os .Stdout )
60+ w .AppendBulk (data )
61+ w .SetBorder (false )
62+ w .SetColumnSeparator (":" )
63+ w .SetColumnAlignment ([]int {tablewriter .ALIGN_RIGHT , tablewriter .ALIGN_LEFT })
64+
65+ fmt .Println ()
66+ w .Render ()
67+ fmt .Println ()
68+ }
69+
70+ func userRoleNames (user api.User ) []string {
71+ names := make ([]string , len (user .Roles ))
72+ for i , r := range user .Roles {
73+ names [i ] = r .Name
74+ }
75+ return names
5176}
0 commit comments