image/tree: Unmark as experimental, warn when redirected

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-07-24 18:11:34 +02:00
parent f214f860b6
commit 9257cc7f68

View File

@ -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
}