forked from cloudfoundry/cli
/
staging_security_groups_command.go
52 lines (42 loc) · 1.26 KB
/
staging_security_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
package v7
import (
"code.cloudfoundry.org/cli/util/ui"
)
type StagingSecurityGroupsCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME staging-security-groups"`
relatedCommands interface{} `related_commands:"bind-staging-security-group, security-group, unbind-staging-security-group"`
}
func (cmd StagingSecurityGroupsCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Getting global staging security groups as {{.Username}}...", map[string]interface{}{
"Username": user.Name,
})
cmd.UI.DisplayNewline()
stagingSecurityGroups, warnings, err := cmd.Actor.GetGlobalStagingSecurityGroups()
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
if len(stagingSecurityGroups) == 0 {
cmd.UI.DisplayText("No global staging security groups found.")
return nil
}
table := [][]string{{
cmd.UI.TranslateText("name"),
}}
for _, stagingSecurityGroup := range stagingSecurityGroups {
table = append(table, []string{
cmd.UI.TranslateText(stagingSecurityGroup.Name),
})
}
cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
return nil
}