forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_routes.go
62 lines (53 loc) · 1.34 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
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(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
reqs = append(reqs, reqFactory.NewLoginRequirement())
return
}
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
apiResponse := 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 apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Failed fetching routes.\n%s", apiResponse.Message)
return
}
if noRoutes {
cmd.ui.Say("No routes found")
}
}