/
router_groups_command.go
62 lines (49 loc) · 1.29 KB
/
router_groups_command.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
package v7
import (
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/util/ui"
)
type RouterGroupsCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME router-groups"`
relatedCommands interface{} `related_commands:"create-domain, domains"`
}
func (cmd RouterGroupsCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
currentUser, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Getting router groups as {{.CurrentUser}}...", map[string]interface{}{
"CurrentUser": currentUser.Name,
})
cmd.UI.DisplayNewline()
routerGroups, err := cmd.Actor.GetRouterGroups()
if err != nil {
return err
}
if len(routerGroups) == 0 {
cmd.UI.DisplayText("No router groups found.")
} else {
cmd.displayRouterGroupsTable(routerGroups)
}
return nil
}
func (cmd RouterGroupsCommand) displayRouterGroupsTable(routerGroups []v7action.RouterGroup) {
var table = [][]string{
{
cmd.UI.TranslateText("name"),
cmd.UI.TranslateText("type"),
},
}
for _, routerGroup := range routerGroups {
table = append(table, []string{
routerGroup.Name,
routerGroup.Type,
})
}
cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
}