@@ -6,13 +6,15 @@ package image
66import (
77 "context"
88 "fmt"
9+ "os"
910 "slices"
1011 "sort"
1112 "strings"
1213
1314 "github.com/containerd/platforms"
1415 "github.com/docker/cli/cli/command"
1516 "github.com/docker/cli/cli/command/formatter"
17+ "github.com/docker/cli/cli/streams"
1618 "github.com/docker/cli/internal/tui"
1719 "github.com/docker/go-units"
1820 "github.com/moby/moby/api/types/filters"
@@ -191,6 +193,10 @@ func getPossibleChips(view treeView) (chips []imageChip) {
191193}
192194
193195func printImageTree (dockerCLI command.Cli , view treeView ) error {
196+ if streamRedirected (dockerCLI .Out ()) {
197+ _ , _ = fmt .Fprintln (dockerCLI .Err (), "WARNING: This output is designed for human readability. For machine-readable output, please use --format." )
198+ }
199+
194200 out := tui .NewOutput (dockerCLI .Out ())
195201 _ , width := out .GetTtySize ()
196202 if width == 0 {
@@ -205,10 +211,7 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
205211 untaggedColor := out .Color (tui .ColorTertiary )
206212 isTerm := out .IsTerminal ()
207213
208- out .PrintlnWithColor (tui .ColorWarning , "WARNING: This is an experimental feature. The output may change and shouldn't be depended on." )
209-
210214 out .Println (generateLegend (out , width ))
211- out .Println ()
212215
213216 possibleChips := getPossibleChips (view )
214217 columns := []imgColumn {
@@ -488,3 +491,17 @@ func widestFirstColumnValue(headers []imgColumn, images []topImage) int {
488491 }
489492 return width
490493}
494+
495+ func streamRedirected (s * streams.Out ) bool {
496+ fd := s .FD ()
497+ if os .Stdout .Fd () != fd {
498+ return true
499+ }
500+
501+ fi , err := os .Stdout .Stat ()
502+ if err != nil {
503+ return true
504+ }
505+
506+ return fi .Mode ()& os .ModeCharDevice == 0
507+ }
0 commit comments