/
users.go
80 lines (72 loc) · 2.34 KB
/
users.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package output
import (
"fmt"
"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
"github.com/plouc/go-gitlab-client/gitlab"
"io"
)
func Users(w io.Writer, format string, collection *gitlab.UserCollection) {
if format == "json" {
collection.RenderJson(w)
} else if format == "yaml" {
collection.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
table := tablewriter.NewWriter(w)
table.SetHeader([]string{
"Id",
"Username",
"Email",
"Name",
"State",
"Is admin",
"External",
})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
for _, user := range collection.Items {
table.Append([]string{
fmt.Sprintf("%d", user.Id),
user.Username,
user.Email,
user.Name,
user.State,
fmt.Sprintf("%t", user.IsAdmin),
fmt.Sprintf("%t", user.External),
})
}
table.Render()
fmt.Fprintln(w, "")
}
}
func User(w io.Writer, format string, user *gitlab.User) {
if format == "json" {
user.RenderJson(w)
} else if format == "yaml" {
user.RenderYaml(w)
} else {
fmt.Fprintln(w, "")
fmt.Fprintln(w, "Basic info")
fmt.Fprintf(w, " Id %s\n", color.YellowString("%d", user.Id))
fmt.Fprintf(w, " Username %s\n", color.YellowString(user.Username))
fmt.Fprintf(w, " Email %s\n", color.YellowString(user.Email))
fmt.Fprintf(w, " Name %s\n", color.YellowString(user.Name))
fmt.Fprintf(w, " State %s\n", color.YellowString(user.State))
fmt.Fprintln(w, "")
fmt.Fprintln(w, "Rights")
fmt.Fprintf(w, " IsAdmin %s\n", color.YellowString("%t", user.IsAdmin))
fmt.Fprintf(w, " CanCreateGroup %s\n", color.YellowString("%t", user.CanCreateGroup))
fmt.Fprintf(w, " CanCreateProject %s\n", color.YellowString("%t", user.CanCreateProject))
fmt.Fprintf(w, " ProjectsLimit %s\n", color.YellowString("%d", user.ProjectsLimit))
fmt.Fprintln(w, "")
fmt.Fprintln(w, "Security")
fmt.Fprintf(w, " External %s\n", color.YellowString("%t", user.External))
fmt.Fprintf(w, " TwoFactorEnabled %s\n", color.YellowString("%t", user.TwoFactorEnabled))
fmt.Fprintln(w, " Identities")
for _, identity := range user.Identities {
fmt.Fprintf(w, " - Provider %s\n", color.YellowString(identity.Provider))
fmt.Fprintf(w, " ExternUid %s\n", color.YellowString(identity.ExternUid))
}
fmt.Fprintln(w, "")
}
}