From 9257cc7f681f204799ae61bd55dcec64458de8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 24 Jul 2025 18:11:34 +0200 Subject: [PATCH] image/tree: Unmark as experimental, warn when redirected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 831ea7529..8fc2f52b3 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -6,6 +6,7 @@ package image import ( "context" "fmt" + "os" "slices" "sort" "strings" @@ -13,6 +14,7 @@ import ( "github.com/containerd/platforms" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + "github.com/docker/cli/cli/streams" "github.com/docker/cli/internal/tui" "github.com/docker/go-units" "github.com/moby/moby/api/types/filters" @@ -191,6 +193,10 @@ func getPossibleChips(view treeView) (chips []imageChip) { } func printImageTree(dockerCLI command.Cli, view treeView) error { + if streamRedirected(dockerCLI.Out()) { + _, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING: This output is designed for human readability. For machine-readable output, please use --format.") + } + out := tui.NewOutput(dockerCLI.Out()) _, width := out.GetTtySize() if width == 0 { @@ -205,8 +211,6 @@ func printImageTree(dockerCLI command.Cli, view treeView) error { untaggedColor := out.Color(tui.ColorTertiary) isTerm := out.IsTerminal() - out.PrintlnWithColor(tui.ColorWarning, "WARNING: This is an experimental feature. The output may change and shouldn't be depended on.") - out.Println(generateLegend(out, width)) possibleChips := getPossibleChips(view) @@ -487,3 +491,17 @@ func widestFirstColumnValue(headers []imgColumn, images []topImage) int { } return width } + +func streamRedirected(s *streams.Out) bool { + fd := s.FD() + if os.Stdout.Fd() != fd { + return true + } + + fi, err := os.Stdout.Stat() + if err != nil { + return true + } + + return fi.Mode()&os.ModeCharDevice == 0 +}