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{