Skip to content

Commit 89091df

Browse files
committed
Support showing roles
1 parent 248a2b6 commit 89091df

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

api/users.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ type Users struct {
66
client *Client
77
}
88

9+
type Role struct {
10+
Name string
11+
}
12+
913
type User struct {
10-
Username string
11-
FullName string
12-
IsRoot bool
13-
CreatedAt string
14+
Username string
15+
FullName string
16+
Email string
17+
Company string
18+
CountryCode string
19+
Picture string
20+
IsRoot bool
21+
CreatedAt string
22+
Roles []Role
1423
}
1524

1625
type UserChangeSet struct {

cmd/users.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
package cmd
1616

1717
import (
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

4447
func 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

Comments
 (0)