forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org_command.go
93 lines (74 loc) · 2.44 KB
/
org_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
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
90
91
92
93
package v7
import (
"fmt"
"sort"
"strings"
"code.cloudfoundry.org/cli/command/flag"
)
type OrgCommand struct {
BaseCommand
RequiredArgs flag.Organization `positional-args:"yes"`
GUID bool `long:"guid" description:"Retrieve and display the given org's guid. All other output for the org is suppressed."`
usage interface{} `usage:"CF_NAME org ORG [--guid]"`
relatedCommands interface{} `related_commands:"org-users, orgs"`
}
func (cmd OrgCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
if cmd.GUID {
return cmd.displayOrgGUID()
}
return cmd.displayOrgSummary()
}
func (cmd OrgCommand) displayOrgGUID() error {
org, warnings, err := cmd.Actor.GetOrganizationByName(cmd.RequiredArgs.Organization)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayText(org.GUID)
return nil
}
func (cmd OrgCommand) displayOrgSummary() error {
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor(
"Getting info for org {{.OrgName}} as {{.Username}}...",
map[string]interface{}{
"OrgName": cmd.RequiredArgs.Organization,
"Username": user.Name,
})
cmd.UI.DisplayNewline()
orgSummary, warnings, err := cmd.Actor.GetOrganizationSummaryByName(cmd.RequiredArgs.Organization)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
table := [][]string{
{cmd.UI.TranslateText("name:"), orgSummary.Name},
{cmd.UI.TranslateText("domains:"), strings.Join(orgSummary.DomainNames, ", ")},
{cmd.UI.TranslateText("quota:"), orgSummary.QuotaName},
{cmd.UI.TranslateText("spaces:"), strings.Join(orgSummary.SpaceNames, ", ")},
}
isolationSegments, v7Warnings, err := cmd.Actor.GetIsolationSegmentsByOrganization(orgSummary.GUID)
cmd.UI.DisplayWarnings(v7Warnings)
if err != nil {
return err
}
isolationSegmentNames := []string{}
for _, iso := range isolationSegments {
if iso.GUID == orgSummary.DefaultIsolationSegmentGUID {
isolationSegmentNames = append(isolationSegmentNames, fmt.Sprintf("%s (%s)", iso.Name, cmd.UI.TranslateText("default")))
} else {
isolationSegmentNames = append(isolationSegmentNames, iso.Name)
}
}
sort.Strings(isolationSegmentNames)
table = append(table, []string{cmd.UI.TranslateText("isolation segments:"), strings.Join(isolationSegmentNames, ", ")})
cmd.UI.DisplayKeyValueTable("", table, 3)
return nil
}