github.com/sleungcy-sap/cli@v7.1.0+incompatible/command/v7/service_brokers_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/resources" 5 "code.cloudfoundry.org/cli/util/ui" 6 ) 7 8 type ServiceBrokersCommand struct { 9 BaseCommand 10 11 usage interface{} `usage:"CF_NAME service-brokers"` 12 relatedCommands interface{} `related_commands:"delete-service-broker, disable-service-access, enable-service-access"` 13 } 14 15 func (cmd *ServiceBrokersCommand) Execute(args []string) error { 16 err := cmd.SharedActor.CheckTarget(false, false) 17 if err != nil { 18 return err 19 } 20 21 currentUser, err := cmd.Config.CurrentUser() 22 if err != nil { 23 return err 24 } 25 26 cmd.UI.DisplayTextWithFlavor("Getting service brokers as {{.Username}}...", map[string]interface{}{"Username": currentUser.Name}) 27 28 serviceBrokers, warnings, err := cmd.Actor.GetServiceBrokers() 29 cmd.UI.DisplayWarnings(warnings) 30 if err != nil { 31 return err 32 } 33 34 cmd.displayServiceBrokers(serviceBrokers) 35 36 return nil 37 } 38 39 func (cmd *ServiceBrokersCommand) displayServiceBrokers(serviceBrokers []resources.ServiceBroker) { 40 if len(serviceBrokers) == 0 { 41 cmd.UI.DisplayText("No service brokers found") 42 } else { 43 cmd.displayServiceBrokersTable(serviceBrokers) 44 } 45 } 46 47 func (cmd *ServiceBrokersCommand) displayServiceBrokersTable(serviceBrokers []resources.ServiceBroker) { 48 var table = [][]string{ 49 { 50 cmd.UI.TranslateText("name"), 51 cmd.UI.TranslateText("url"), 52 }, 53 } 54 55 for _, serviceBroker := range serviceBrokers { 56 table = append(table, []string{serviceBroker.Name, serviceBroker.URL}) 57 } 58 59 cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding) 60 }