forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_routes.go
64 lines (55 loc) · 1.39 KB
/
list_routes.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
package route
import (
"cf/api"
"cf/configuration"
"cf/models"
"cf/requirements"
"cf/terminal"
"github.com/codegangsta/cli"
"strings"
)
type ListRoutes struct {
ui terminal.UI
routeRepo api.RouteRepository
config configuration.Reader
}
func NewListRoutes(ui terminal.UI, config configuration.Reader, routeRepo api.RouteRepository) (cmd ListRoutes) {
cmd.ui = ui
cmd.config = config
cmd.routeRepo = routeRepo
return
}
func (cmd ListRoutes) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) ([]requirements.Requirement, error) {
return []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
}, nil
}
func (cmd ListRoutes) Run(c *cli.Context) {
cmd.ui.Say("Getting routes as %s ...\n",
terminal.EntityNameColor(cmd.config.Username()),
)
table := cmd.ui.Table([]string{"host", "domain", "apps"})
noRoutes := true
apiErr := cmd.routeRepo.ListRoutes(func(route models.Route) bool {
appNames := ""
for _, app := range route.Apps {
appNames = appNames + ", " + app.Name
}
appNames = strings.TrimPrefix(appNames, ", ")
table.Print([][]string{{
route.Host,
route.Domain.Name,
appNames,
}})
noRoutes = false
return true
})
if apiErr != nil {
cmd.ui.Failed("Failed fetching routes.\n%s", apiErr.Error())
return
}
if noRoutes {
cmd.ui.Say("No routes found")
}
}