Merge pull request #439 from ripcurld0/fix_image_ls_digest

Show images digests when "{{.Digest}}" is in format
This commit is contained in:
Vincent Demeester 2017-08-22 16:17:43 +02:00 committed by GitHub
commit 317b735573
2 changed files with 14 additions and 1 deletions

View File

@ -79,6 +79,11 @@ func ImageWrite(ctx ImageContext, images []types.ImageSummary) error {
return ctx.Write(newImageContext(), render) return ctx.Write(newImageContext(), render)
} }
// needDigest determines whether the image digest should be ignored or not when writing image context
func needDigest(ctx ImageContext) bool {
return ctx.Digest || ctx.Format.Contains("{{.Digest}}")
}
func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subContext subContext) error) error { func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subContext subContext) error) error {
for _, image := range images { for _, image := range images {
images := []*imageContext{} images := []*imageContext{}
@ -121,7 +126,7 @@ func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subC
// Do not display digests as their own row // Do not display digests as their own row
delete(repoDigests, repo) delete(repoDigests, repo)
if !ctx.Digest { if !needDigest(ctx) {
// Ignore digest references, just show tag once // Ignore digest references, just show tag once
digests = nil digests = nil
} }

View File

@ -137,6 +137,14 @@ image <none>
}, },
"REPOSITORY\nimage\nimage\n<none>\n", "REPOSITORY\nimage\nimage\n<none>\n",
}, },
{
ImageContext{
Context: Context{
Format: NewImageFormat("table {{.Digest}}", true, false),
},
},
"DIGEST\nsha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf\n<none>\n<none>\n",
},
{ {
ImageContext{ ImageContext{
Context: Context{ Context: Context{