forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
83 lines (76 loc) · 2.18 KB
/
ui.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
81
82
83
package userprint
import (
. "code.cloudfoundry.org/cli/cf/i18n"
"code.cloudfoundry.org/cli/cf/models"
"code.cloudfoundry.org/cli/cf/terminal"
)
type SpaceUsersUIPrinter struct {
UI terminal.UI
UserLister func(spaceGUID string, role models.Role) ([]models.UserFields, error)
Roles []models.Role
RoleDisplayNames map[models.Role]string
}
type OrgUsersUIPrinter struct {
Roles []models.Role
RoleDisplayNames map[models.Role]string
UserLister func(orgGUID string, role models.Role) ([]models.UserFields, error)
UI terminal.UI
}
func (p *OrgUsersUIPrinter) PrintUsers(guid string, username string) {
for _, role := range p.Roles {
displayName := p.RoleDisplayNames[role]
users, err := p.UserLister(guid, role)
if err != nil {
p.UI.Failed(T("Failed fetching org-users for role {{.OrgRoleToDisplayName}}.\n{{.Error}}",
map[string]interface{}{
"Error": err.Error(),
"OrgRoleToDisplayName": displayName,
}))
return
}
p.UI.Say("")
p.UI.Say("%s", terminal.HeaderColor(displayName))
if len(users) == 0 {
p.UI.Say(" " + T("No {{.Role}} found", map[string]interface{}{
"Role": displayName,
}))
} else {
for _, user := range users {
if len(user.Username) > 0 {
p.UI.Say(" %s", user.Username)
} else {
p.UI.Say(" %s (client)", user.GUID)
}
}
}
}
}
func (p *SpaceUsersUIPrinter) PrintUsers(guid string, username string) {
for _, role := range p.Roles {
displayName := p.RoleDisplayNames[role]
users, err := p.UserLister(guid, role)
if err != nil {
p.UI.Failed(T("Failed fetching space-users for role {{.SpaceRoleToDisplayName}}.\n{{.Error}}",
map[string]interface{}{
"Error": err.Error(),
"SpaceRoleToDisplayName": displayName,
}))
return
}
p.UI.Say("")
p.UI.Say("%s", terminal.HeaderColor(displayName))
if len(users) == 0 {
p.UI.Say(" " + T("No {{.Role}} found", map[string]interface{}{
"Role": displayName,
}))
} else {
for _, user := range users {
if len(user.Username) > 0 {
p.UI.Say(" %s", user.Username)
} else {
p.UI.Say(" %s (client)", user.GUID)
}
}
}
}
}