github.com/sleungcy-sap/cli@v7.1.0+incompatible/command/v7/domains_command.go (about) 1 package v7 2 3 import ( 4 "sort" 5 "strings" 6 7 "code.cloudfoundry.org/cli/resources" 8 "code.cloudfoundry.org/cli/util/sorting" 9 "code.cloudfoundry.org/cli/util/ui" 10 ) 11 12 type DomainsCommand struct { 13 BaseCommand 14 15 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)'"` 16 relatedCommands interface{} `related_commands:"create-private-domain, create-route, create-shared-domain, routes, set-label"` 17 Labels string `long:"labels" description:"Selector to filter domains by labels"` 18 } 19 20 func (cmd DomainsCommand) Execute(args []string) error { 21 err := cmd.SharedActor.CheckTarget(true, false) 22 if err != nil { 23 return err 24 } 25 26 currentUser, err := cmd.Config.CurrentUser() 27 if err != nil { 28 return err 29 } 30 31 targetedOrg := cmd.Config.TargetedOrganization() 32 cmd.UI.DisplayTextWithFlavor("Getting domains in org {{.CurrentOrg}} as {{.CurrentUser}}...\n", map[string]interface{}{ 33 "CurrentOrg": targetedOrg.Name, 34 "CurrentUser": currentUser.Name, 35 }) 36 37 domains, warnings, err := cmd.Actor.GetOrganizationDomains(targetedOrg.GUID, cmd.Labels) 38 cmd.UI.DisplayWarnings(warnings) 39 if err != nil { 40 return err 41 } 42 43 sort.Slice(domains, func(i, j int) bool { return sorting.LessIgnoreCase(domains[i].Name, domains[j].Name) }) 44 45 if len(domains) > 0 { 46 cmd.displayDomainsTable(domains) 47 } else { 48 cmd.UI.DisplayText("No domains found.") 49 } 50 return nil 51 } 52 53 func (cmd DomainsCommand) displayDomainsTable(domains []resources.Domain) { 54 var domainsTable = [][]string{ 55 { 56 cmd.UI.TranslateText("name"), 57 cmd.UI.TranslateText("availability"), 58 cmd.UI.TranslateText("internal"), 59 cmd.UI.TranslateText("protocols"), 60 }, 61 } 62 63 for _, domain := range domains { 64 var availability string 65 var internal string 66 67 if domain.Shared() { 68 availability = cmd.UI.TranslateText("shared") 69 } else { 70 availability = cmd.UI.TranslateText("private") 71 } 72 73 if domain.Internal.IsSet && domain.Internal.Value { 74 internal = cmd.UI.TranslateText("true") 75 } 76 77 domainsTable = append(domainsTable, []string{ 78 domain.Name, 79 availability, 80 internal, 81 strings.Join(domain.Protocols, ","), 82 }) 83 } 84 85 cmd.UI.DisplayTableWithHeader("", domainsTable, ui.DefaultTableSpacePadding) 86 87 }