mirror of https://github.com/docker/cli.git
Fix docker ps table headers with custom format and "split" or "join"
Update the list of overrides for table headers so that columns using split or join will produce the correct table header. Before this patch: docker ps --format='table {{split .Names "/"}}' [NAMES] [unruffled_mclean] [eloquent_meitner] [sleepy_grothendieck] With this patch applied: docker ps --format='table {{split .Names "/"}}' NAMES [unruffled_mclean] [eloquent_meitner] [sleepy_grothendieck] Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
69f216f6e4
commit
aef6b04a7c
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue