-
Notifications
You must be signed in to change notification settings - Fork 927
/
show_space.go
69 lines (60 loc) · 1.85 KB
/
show_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
package space
import (
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
"strings"
)
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) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "space")
return
}
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("Getting info for space %s in org %s as %s...",
terminal.EntityNameColor(space.Name),
terminal.EntityNameColor(space.Organization.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
cmd.ui.Ok()
cmd.ui.Say("\n%s:", terminal.EntityNameColor(space.Name))
cmd.ui.Say(" Org: %s", terminal.EntityNameColor(space.Organization.Name))
apps := []string{}
for _, app := range space.Applications {
apps = append(apps, app.Name)
}
cmd.ui.Say(" Apps: %s", terminal.EntityNameColor(strings.Join(apps, ", ")))
domains := []string{}
for _, domain := range space.Domains {
domains = append(domains, domain.Name)
}
cmd.ui.Say(" Domains: %s", terminal.EntityNameColor(strings.Join(domains, ", ")))
services := []string{}
for _, service := range space.ServiceInstances {
services = append(services, service.Name)
}
cmd.ui.Say(" Services: %s", terminal.EntityNameColor(strings.Join(services, ", ")))
}