Skip to content

Commit 80e8fda

Browse files
dmkendeloof
authored andcommitted
compose top: ensure CMD is right-most column
Signed-off-by: Dominik Menke <[email protected]>
1 parent 375a279 commit 80e8fda

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

cmd/compose/top.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ func collectTop(containers []api.ContainerProcSummary) (topHeader, []topEntries)
101101
entries = append(entries, entry)
102102
}
103103
}
104+
105+
// ensure CMD is the right-most column
106+
if pos, ok := header["CMD"]; ok {
107+
max := pos
108+
for h, i := range header {
109+
if i > max {
110+
max = i
111+
}
112+
if i > pos {
113+
header[h] = i - 1
114+
}
115+
}
116+
header["CMD"] = max
117+
}
118+
104119
return header, entries
105120
}
106121

cmd/compose/top_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ func TestRunTopCore(t *testing.T) {
245245
"STIME": 6,
246246
"TTY": 7,
247247
"TIME": 8,
248-
"CMD": 9,
249-
"GID": 10,
248+
"GID": 9,
249+
"CMD": 10,
250250
}, header)
251251
assert.EqualValues(t, []topEntries{
252252
{
@@ -311,12 +311,12 @@ func TestRunTopCore(t *testing.T) {
311311
err := topPrint(&buf, header, entries)
312312
require.NoError(t, err)
313313
assert.Equal(t, trim(`
314-
SERVICE # UID PID PPID C STIME TTY TIME CMD GID
315-
simple 1 root 1 1 0 12:00 ? 00:00:01 /entrypoint -
316-
noppid 1 root 1 - 0 12:00 ? 00:00:02 /entrypoint -
317-
extra-hdr 1 root 1 1 0 12:00 ? 00:00:03 /entrypoint 1
318-
multiple 1 root 1 1 0 12:00 ? 00:00:04 /entrypoint -
319-
multiple 1 root 123 1 0 12:00 ? 00:00:42 sleep infinity -
314+
SERVICE # UID PID PPID C STIME TTY TIME GID CMD
315+
simple 1 root 1 1 0 12:00 ? 00:00:01 - /entrypoint
316+
noppid 1 root 1 - 0 12:00 ? 00:00:02 - /entrypoint
317+
extra-hdr 1 root 1 1 0 12:00 ? 00:00:03 1 /entrypoint
318+
multiple 1 root 1 1 0 12:00 ? 00:00:04 - /entrypoint
319+
multiple 1 root 123 1 0 12:00 ? 00:00:42 - sleep infinity
320320
`), buf.String())
321321

322322
})

0 commit comments

Comments
 (0)