@@ -6,13 +6,15 @@ package image
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "os"
9
10
"slices"
10
11
"sort"
11
12
"strings"
12
13
13
14
"github.com/containerd/platforms"
14
15
"github.com/docker/cli/cli/command"
15
16
"github.com/docker/cli/cli/command/formatter"
17
+ "github.com/docker/cli/cli/streams"
16
18
"github.com/docker/cli/internal/tui"
17
19
"github.com/docker/go-units"
18
20
"github.com/moby/moby/api/types/filters"
@@ -191,6 +193,10 @@ func getPossibleChips(view treeView) (chips []imageChip) {
191
193
}
192
194
193
195
func 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
+
194
200
out := tui .NewOutput (dockerCLI .Out ())
195
201
_ , width := out .GetTtySize ()
196
202
if width == 0 {
@@ -205,10 +211,7 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
205
211
untaggedColor := out .Color (tui .ColorTertiary )
206
212
isTerm := out .IsTerminal ()
207
213
208
- out .PrintlnWithColor (tui .ColorWarning , "WARNING: This is an experimental feature. The output may change and shouldn't be depended on." )
209
-
210
214
out .Println (generateLegend (out , width ))
211
- out .Println ()
212
215
213
216
possibleChips := getPossibleChips (view )
214
217
columns := []imgColumn {
@@ -488,3 +491,17 @@ func widestFirstColumnValue(headers []imgColumn, images []topImage) int {
488
491
}
489
492
return width
490
493
}
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