diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index b0637da8ff..18740d5499 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -241,6 +241,10 @@ size: 0B Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)}, string(golden.Get(t, "container-context-write-special-headers.golden")), }, + { + Context{Format: NewContainerFormat(`table {{split .Image ":"}}`, false, false)}, + "IMAGE\n[ubuntu]\n[ubuntu]\n", + }, } for _, testcase := range cases { diff --git a/templates/templates.go b/templates/templates.go index 6cc2ec3608..0e8dd15368 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -30,11 +30,23 @@ var basicFunctions = template.FuncMap{ // HeaderFunctions are used to created headers of a table. // This is a replacement of basicFunctions for header generation // because we want the header to remain intact. -// Some functions like `split` are irrelevant so not added. +// Some functions like `pad` are not overridden (to preserve alignment +// with the columns). var HeaderFunctions = template.FuncMap{ "json": func(v string) string { return v }, + "split": func(v string, _ string) string { + // we want the table header to show the name of the column, and not + // split the table header itself. Using a different signature + // here, and return a string instead of []string + return v + }, + "join": func(v string, _ string) string { + // table headers are always a string, so use a different signature + // for the "join" function (string instead of []string) + return v + }, "title": func(v string) string { return v },