MCPcopy
hub / github.com/docker/compose / topPrint

Function topPrint

cmd/compose/top.go:122–149  ·  cmd/compose/top.go::topPrint
(out io.Writer, headers topHeader, rows []topEntries)

Source from the content-addressed store, hash-verified

120}
121
122func topPrint(out io.Writer, headers topHeader, rows []topEntries) error {
123 if len(rows) == 0 {
124 return nil
125 }
126
127 w := tabwriter.NewWriter(out, 4, 1, 2, ' ', 0)
128
129 // write headers in the order we've encountered them
130 h := make([]string, len(headers))
131 for title, index := range headers {
132 h[index] = title
133 }
134 _, _ = fmt.Fprintln(w, strings.Join(h, "\t"))
135
136 for _, row := range rows {
137 // write proc data in header order
138 r := make([]string, len(headers))
139 for title, index := range headers {
140 if v, ok := row[title]; ok {
141 r[index] = v
142 } else {
143 r[index] = "-"
144 }
145 }
146 _, _ = fmt.Fprintln(w, strings.Join(r, "\t"))
147 }
148 return w.Flush()
149}

Callers 2

runTopFunction · 0.85
TestRunTopCoreFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestRunTopCoreFunction · 0.68