From 83112f634371dde5bf68f1f0ddce0f94bd98cf21 Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Mon, 14 Aug 2017 12:06:31 +0300 Subject: [PATCH] Show images digests when "{{.Digest}}" is in format This patch fixes the following bug: Running "docker image ls --digests" will add images digests to the image table. However, when using "format" to display images digests all of them are "". Signed-off-by: Boaz Shuster --- cli/command/formatter/image.go | 7 ++++++- cli/command/formatter/image_test.go | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/command/formatter/image.go b/cli/command/formatter/image.go index cbd3edad3c..aaf8ff1aa1 100644 --- a/cli/command/formatter/image.go +++ b/cli/command/formatter/image.go @@ -79,6 +79,11 @@ func ImageWrite(ctx ImageContext, images []types.ImageSummary) error { 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 { for _, image := range images { images := []*imageContext{} @@ -121,7 +126,7 @@ func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subC // Do not display digests as their own row delete(repoDigests, repo) - if !ctx.Digest { + if !needDigest(ctx) { // Ignore digest references, just show tag once digests = nil } diff --git a/cli/command/formatter/image_test.go b/cli/command/formatter/image_test.go index b3c4cc8094..be7b084e3c 100644 --- a/cli/command/formatter/image_test.go +++ b/cli/command/formatter/image_test.go @@ -137,6 +137,14 @@ image }, "REPOSITORY\nimage\nimage\n\n", }, + { + ImageContext{ + Context: Context{ + Format: NewImageFormat("table {{.Digest}}", true, false), + }, + }, + "DIGEST\nsha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf\n\n\n", + }, { ImageContext{ Context: Context{