forked from HuaweiTech/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
64 lines (53 loc) · 1.38 KB
/
ui.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 ui_helpers
import (
"fmt"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/terminal"
"strings"
)
func ColoredAppState(app models.ApplicationFields) string {
appState := strings.ToLower(app.State)
if app.RunningInstances == 0 {
if appState == "stopped" {
return appState
} else {
return terminal.CrashedColor(appState)
}
}
if app.RunningInstances < app.InstanceCount {
return terminal.WarningColor(appState)
}
return appState
}
func ColoredAppInstances(app models.ApplicationFields) string {
healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)
if app.RunningInstances == 0 {
if strings.ToLower(app.State) == "stopped" {
return healthString
} else {
return terminal.CrashedColor(healthString)
}
}
if app.RunningInstances < app.InstanceCount {
return terminal.WarningColor(healthString)
}
return healthString
}
func ColoredInstanceState(instance models.AppInstanceFields) (colored string) {
state := string(instance.State)
switch state {
case "started", "running":
colored = "running"
case "stopped":
colored = terminal.StoppedColor("stopped")
case "flapping":
colored = terminal.CrashedColor("crashing")
case "down":
colored = terminal.CrashedColor("down")
case "starting":
colored = terminal.AdvisoryColor("starting")
default:
colored = terminal.WarningColor(state)
}
return
}