forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.go
89 lines (74 loc) · 2.57 KB
/
space.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
84
85
86
87
88
89
package space
import (
"strings"
"github.com/cloudfoundry/cli/cf/command_metadata"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/codegangsta/cli"
)
type ShowSpace struct {
ui terminal.UI
config configuration.Reader
spaceReq requirements.SpaceRequirement
}
func NewShowSpace(ui terminal.UI, config configuration.Reader) (cmd *ShowSpace) {
cmd = new(ShowSpace)
cmd.ui = ui
cmd.config = config
return
}
func (cmd *ShowSpace) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "space",
Description: T("Show space info"),
Usage: T("CF_NAME space SPACE"),
}
}
func (cmd *ShowSpace) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}
cmd.spaceReq = requirementsFactory.NewSpaceRequirement(c.Args()[0])
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedOrgRequirement(),
cmd.spaceReq,
}
return
}
func (cmd *ShowSpace) Run(c *cli.Context) {
space := cmd.spaceReq.GetSpace()
cmd.ui.Say(T("Getting info for space {{.TargetSpace}} in org {{.OrgName}} as {{.CurrentUser}}...",
map[string]interface{}{
"TargetSpace": terminal.EntityNameColor(space.Name),
"OrgName": terminal.EntityNameColor(space.Organization.Name),
"CurrentUser": terminal.EntityNameColor(cmd.config.Username()),
}))
cmd.ui.Ok()
cmd.ui.Say("")
cmd.ui.Say(terminal.EntityNameColor(space.Name) + ":")
table := terminal.NewTable(cmd.ui, []string{"", "", ""})
table.Add("", T("Org:"), terminal.EntityNameColor(space.Organization.Name))
apps := []string{}
for _, app := range space.Applications {
apps = append(apps, terminal.EntityNameColor(app.Name))
}
table.Add("", T("Apps:"), strings.Join(apps, ", "))
domains := []string{}
for _, domain := range space.Domains {
domains = append(domains, terminal.EntityNameColor(domain.Name))
}
table.Add("", T("Domains:"), strings.Join(domains, ", "))
services := []string{}
for _, service := range space.ServiceInstances {
services = append(services, terminal.EntityNameColor(service.Name))
}
table.Add("", T("Services:"), strings.Join(services, ", "))
securityGroups := []string{}
for _, group := range space.SecurityGroups {
securityGroups = append(securityGroups, terminal.EntityNameColor(group.Name))
}
table.Add("", T("Security Groups:"), strings.Join(securityGroups, ", "))
table.Print()
}