-
Notifications
You must be signed in to change notification settings - Fork 927
/
domains_command.go
87 lines (70 loc) · 2.31 KB
/
domains_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
package v7
import (
"sort"
"strings"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/util/sorting"
"code.cloudfoundry.org/cli/util/ui"
)
type DomainsCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME domains\n\nEXAMPLES:\n CF_NAME domains\n CF_NAME domains --labels 'environment in (production,staging),tier in (backend)'\n CF_NAME domains --labels 'env=dev,!chargeback-code,tier in (backend,worker)'"`
relatedCommands interface{} `related_commands:"create-private-domain, create-route, create-shared-domain, routes, set-label"`
Labels string `long:"labels" description:"Selector to filter domains by labels"`
}
func (cmd DomainsCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, false)
if err != nil {
return err
}
currentUser, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
targetedOrg := cmd.Config.TargetedOrganization()
cmd.UI.DisplayTextWithFlavor("Getting domains in org {{.CurrentOrg}} as {{.CurrentUser}}...\n", map[string]interface{}{
"CurrentOrg": targetedOrg.Name,
"CurrentUser": currentUser.Name,
})
domains, warnings, err := cmd.Actor.GetOrganizationDomains(targetedOrg.GUID, cmd.Labels)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
sort.Slice(domains, func(i, j int) bool { return sorting.LessIgnoreCase(domains[i].Name, domains[j].Name) })
if len(domains) > 0 {
cmd.displayDomainsTable(domains)
} else {
cmd.UI.DisplayText("No domains found.")
}
return nil
}
func (cmd DomainsCommand) displayDomainsTable(domains []resources.Domain) {
var domainsTable = [][]string{
{
cmd.UI.TranslateText("name"),
cmd.UI.TranslateText("availability"),
cmd.UI.TranslateText("internal"),
cmd.UI.TranslateText("protocols"),
},
}
for _, domain := range domains {
var availability string
var internal string
if domain.Shared() {
availability = cmd.UI.TranslateText("shared")
} else {
availability = cmd.UI.TranslateText("private")
}
if domain.Internal.IsSet && domain.Internal.Value {
internal = cmd.UI.TranslateText("true")
}
domainsTable = append(domainsTable, []string{
domain.Name,
availability,
internal,
strings.Join(domain.Protocols, ","),
})
}
cmd.UI.DisplayTableWithHeader("", domainsTable, ui.DefaultTableSpacePadding)
}