From d84396d4ebf1df978c1dc7bc3dab15dd93164730 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 20 Nov 2025 15:43:09 +0000 Subject: [PATCH] image ls: allow custom format in cli config Setting a custom format in the cli cofig should still be supported, and not produce an error when specifying "--tree". Specifyihg both "--tree" and "--format" still produces an error, but we could consider allowing "json" format in a future update. Signed-off-by: Sebastiaan van Stijn --- cli/command/image/list.go | 19 ++++++++++--------- .../list-command-success.format.golden | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/command/image/list.go b/cli/command/image/list.go index 9652d9fd5..40915b892 100644 --- a/cli/command/image/list.go +++ b/cli/command/image/list.go @@ -114,6 +114,16 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions } } + format := options.format + if len(format) == 0 { + if len(dockerCLI.ConfigFile().ImagesFormat) > 0 && !options.quiet && !options.tree { + format = dockerCLI.ConfigFile().ImagesFormat + useTree = false + } else { + format = formatter.TableFormatKey + } + } + if useTree { return runTree(ctx, dockerCLI, treeOptions{ images: images, @@ -123,15 +133,6 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions }) } - format := options.format - if len(format) == 0 { - if len(dockerCLI.ConfigFile().ImagesFormat) > 0 && !options.quiet { - format = dockerCLI.ConfigFile().ImagesFormat - } else { - format = formatter.TableFormatKey - } - } - imageCtx := formatter.ImageContext{ Context: formatter.Context{ Output: dockerCLI.Out(), diff --git a/cli/command/image/testdata/list-command-success.format.golden b/cli/command/image/testdata/list-command-success.format.golden index cca2da199..e69de29bb 100644 --- a/cli/command/image/testdata/list-command-success.format.golden +++ b/cli/command/image/testdata/list-command-success.format.golden @@ -1 +0,0 @@ -IMAGE ID DISK USAGE CONTENT SIZE EXTRA