MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ParseV3AppProcessTable

Function ParseV3AppProcessTable

integration/helpers/app_instance_table.go:40–104  ·  view source on GitHub ↗

ParseV3AppProcessTable parses bytes from 'cf app' stdout into an AppTable.

(input []byte)

Source from the content-addressed store, hash-verified

38
39// ParseV3AppProcessTable parses bytes from 'cf app' stdout into an AppTable.
40func ParseV3AppProcessTable(input []byte) AppTable {
41 appTable := AppTable{}
42
43 rows := strings.Split(string(input), "\n")
44 foundFirstProcess := false
45 for _, row := range rows {
46 if !foundFirstProcess {
47 ok := regexp.MustCompile(`\Atype:([^:]+)\z`).Match([]byte(row))
48 if ok {
49 foundFirstProcess = true
50 } else {
51 continue
52 }
53 }
54
55 if row == "" {
56 continue
57 }
58
59 switch {
60 case strings.HasPrefix(row, "#"):
61 // instance row
62 columns := splitColumns(row)
63 instanceRow := AppInstanceRow{
64 Index: columns[0],
65 State: columns[1],
66 Since: columns[2],
67 CPU: columns[3],
68 Memory: columns[4],
69 Disk: columns[5],
70 LogRate: columns[6],
71 CPUEntitlement: columns[7],
72 Details: columns[8],
73 Ready: columns[9],
74 }
75 lastProcessIndex := len(appTable.Processes) - 1
76 appTable.Processes[lastProcessIndex].Instances = append(
77 appTable.Processes[lastProcessIndex].Instances,
78 instanceRow,
79 )
80
81 case strings.HasPrefix(row, "type:"):
82 appTable.Processes = append(appTable.Processes, AppProcessTable{
83 Type: strings.TrimSpace(strings.TrimPrefix(row, "type:")),
84 })
85
86 case strings.HasPrefix(row, "instances:"):
87 lpi := len(appTable.Processes) - 1
88 iVal := strings.TrimSpace(strings.TrimPrefix(row, "instances:"))
89 appTable.Processes[lpi].InstanceCount = iVal
90
91 case strings.HasPrefix(row, "memory usage:"):
92 lpi := len(appTable.Processes) - 1
93 mVal := strings.TrimSpace(strings.TrimPrefix(row, "memory usage:"))
94 appTable.Processes[lpi].MemUsage = mVal
95
96 default:
97 // column headers

Calls 2

splitColumnsFunction · 0.85
MatchMethod · 0.45

Tested by

no test coverage detected