mirror of https://github.com/docker/cli.git
Ignore some functions in the Go template when header is rendered
This fix ignore some functions in the Go template when header is redendered, so that `--format "{{truncate .ID 1}}"` will still be able to redener the header correctly. Additional test cases have been added to the unit test. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
9dda1155f3
commit
82bf90ffbc
|
@ -226,6 +226,14 @@ size: 0B
|
|||
Context{Format: NewContainerFormat("{{.Image}}", false, true)},
|
||||
"ubuntu\nubuntu\n",
|
||||
},
|
||||
// Special headers for customerized table format
|
||||
{
|
||||
Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)},
|
||||
`CONTAINER ID IMAGE CREATED/STATUS/ PORTS .NAMES STATUS
|
||||
conta "ubuntu" 24 hours ago//.FOOBAR_BAZ
|
||||
conta "ubuntu" 24 hours ago//.FOOBAR_BAR
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testcase := range cases {
|
||||
|
|
|
@ -2,13 +2,8 @@ package formatter
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
//"encoding/json"
|
||||
//"strings"
|
||||
"testing"
|
||||
//"time"
|
||||
|
||||
//"github.com/docker/docker/api/types"
|
||||
//"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
)
|
||||
|
||||
|
@ -44,10 +39,6 @@ VOLUME NAME LINKS SIZE
|
|||
}
|
||||
|
||||
for _, testcase := range cases {
|
||||
//networks := []types.NetworkResource{
|
||||
// {ID: "networkID1", Name: "foobar_baz", Driver: "foo", Scope: "local", Created: timestamp1},
|
||||
// {ID: "networkID2", Name: "foobar_bar", Driver: "bar", Scope: "local", Created: timestamp2},
|
||||
//}
|
||||
out := bytes.NewBufferString("")
|
||||
testcase.context.Output = out
|
||||
testcase.context.Write()
|
||||
|
|
|
@ -73,7 +73,7 @@ func (c *Context) postFormat(tmpl *template.Template, subContext subContext) {
|
|||
if c.Format.IsTable() {
|
||||
t := tabwriter.NewWriter(c.Output, 20, 1, 3, ' ', 0)
|
||||
buffer := bytes.NewBufferString("")
|
||||
tmpl.Execute(buffer, subContext.FullHeader())
|
||||
tmpl.Funcs(templates.HeaderFunctions).Execute(buffer, subContext.FullHeader())
|
||||
buffer.WriteTo(t)
|
||||
t.Write([]byte("\n"))
|
||||
c.buffer.WriteTo(t)
|
||||
|
|
|
@ -76,20 +76,6 @@ func ImageWrite(ctx ImageContext, images []types.ImageSummary) error {
|
|||
render := func(format func(subContext subContext) error) error {
|
||||
return imageFormat(ctx, images, format)
|
||||
}
|
||||
imageCtx := imageContext{}
|
||||
imageCtx.header = map[string]string{
|
||||
"ID": imageIDHeader,
|
||||
"Repository": repositoryHeader,
|
||||
"Tag": tagHeader,
|
||||
"Digest": digestHeader,
|
||||
"CreatedSince": createdSinceHeader,
|
||||
"CreatedAt": createdAtHeader,
|
||||
"Size": sizeHeader,
|
||||
"Containers": containersHeader,
|
||||
"VirtualSize": sizeHeader,
|
||||
"SharedSize": sharedSizeHeader,
|
||||
"UniqueSize": uniqueSizeHeader,
|
||||
}
|
||||
return ctx.Write(newImageContext(), render)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue