Skip to content

Commit 3046019

Browse files
authored
Merge pull request docker#6209 from vvoland/image-tree-nonexp
image/tree: Unmark as experimental, warn when redirected
2 parents 1eeb0cc + 9257cc7 commit 3046019

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

cli/command/image/tree.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ package image
66
import (
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

193195
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+
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

Comments
 (0)