github.com/loafoe/cli@v7.1.0+incompatible/command/v7/router_groups_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/v7action" 5 "code.cloudfoundry.org/cli/util/ui" 6 ) 7 8 type RouterGroupsCommand struct { 9 BaseCommand 10 11 usage interface{} `usage:"CF_NAME router-groups"` 12 relatedCommands interface{} `related_commands:"create-domain, domains"` 13 } 14 15 func (cmd RouterGroupsCommand) 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 router groups as {{.CurrentUser}}...", map[string]interface{}{ 27 "CurrentUser": currentUser.Name, 28 }) 29 30 cmd.UI.DisplayNewline() 31 32 routerGroups, err := cmd.Actor.GetRouterGroups() 33 if err != nil { 34 return err 35 } 36 37 if len(routerGroups) == 0 { 38 cmd.UI.DisplayText("No router groups found.") 39 } else { 40 cmd.displayRouterGroupsTable(routerGroups) 41 } 42 43 return nil 44 } 45 46 func (cmd RouterGroupsCommand) displayRouterGroupsTable(routerGroups []v7action.RouterGroup) { 47 var table = [][]string{ 48 { 49 cmd.UI.TranslateText("name"), 50 cmd.UI.TranslateText("type"), 51 }, 52 } 53 54 for _, routerGroup := range routerGroups { 55 table = append(table, []string{ 56 routerGroup.Name, 57 routerGroup.Type, 58 }) 59 } 60 61 cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding) 62 }