-
Notifications
You must be signed in to change notification settings - Fork 986
Expand file tree
/
Copy pathapps_command.go
More file actions
92 lines (72 loc) · 2.52 KB
/
Copy pathapps_command.go
File metadata and controls
92 lines (72 loc) · 2.52 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package v7
import (
"strings"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/util/ui"
)
type AppsCommand struct {
BaseCommand
usage interface{} `usage:"CF_NAME apps [--labels SELECTOR]\n\nEXAMPLES:\n CF_NAME apps\n CF_NAME apps --labels 'environment in (production,staging),tier in (backend)'\n CF_NAME apps --labels 'env=dev,!chargeback-code,tier in (backend,worker)'"`
relatedCommands interface{} `related_commands:"events, logs, map-route, push, scale, start, stop, restart"`
Labels string `long:"labels" description:"Selector to filter apps by labels"`
OmitStats bool `long:"no-stats" description:"Do not retrieve process stats"`
JSONOutput bool `long:"json" description:"Output in json form"`
}
func (cmd AppsCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
user, err := cmd.Actor.GetCurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Getting apps in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": user.Name,
})
cmd.UI.DisplayNewline()
summaries, warnings, err := cmd.Actor.GetAppSummariesForSpace(cmd.Config.TargetedSpace().GUID, cmd.Labels, cmd.OmitStats)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
if cmd.JSONOutput {
return cmd.UI.DisplayJSON("", map[string][]v7action.ApplicationSummary{"apps": summaries})
}
if len(summaries) == 0 {
cmd.UI.DisplayText("No apps found")
return nil
}
fields := []string{
cmd.UI.TranslateText("name"),
cmd.UI.TranslateText("requested state"),
}
if !cmd.OmitStats {
fields = append(fields, cmd.UI.TranslateText("processes"))
}
fields = append(fields, cmd.UI.TranslateText("routes"))
table := [][]string{fields}
for _, summary := range summaries {
tableRow := []string{
summary.Name,
cmd.UI.TranslateText(strings.ToLower(string(summary.State))),
}
if !cmd.OmitStats {
tableRow = append(tableRow, summary.ProcessSummaries.String())
}
tableRow = append(tableRow, getURLs(summary.Routes))
table = append(table, tableRow)
}
cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding)
return nil
}
func getURLs(routes []resources.Route) string {
var routeURLs []string
for _, route := range routes {
routeURLs = append(routeURLs, route.URL)
}
return strings.Join(routeURLs, ", ")
}