mirror of
https://github.com/docker/cli.git
synced 2026-08-24 02:24:17 -05:00
Merge pull request #6754 from MaheshThakur9152/fix/remove-images-redirect-warning
Fix: Remove inconsistent human readability warning from docker images
This commit is contained in:
@@ -211,6 +211,6 @@ func printAmbiguousHint(stdErr io.Writer, matchName string) {
|
||||
"save",
|
||||
"tag":
|
||||
|
||||
_, _ = fmt.Fprintf(stdErr, "\nNo images found matching %q: did you mean \"docker image %[1]s\"?\n", matchName)
|
||||
_, _ = fmt.Fprintf(stdErr, "No images found matching %q: did you mean \"docker image %[1]s\"?\n", matchName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
WARNING: This output is designed for human readability. For machine-readable output, please use --format.
|
||||
|
||||
No images found matching "ls": did you mean "docker image ls"?
|
||||
|
||||
@@ -6,14 +6,12 @@ package image
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
imagetypes "github.com/moby/moby/api/types/image"
|
||||
@@ -241,10 +239,6 @@ func getPossibleChips(view treeView) (chips []imageChip) {
|
||||
}
|
||||
|
||||
func printImageTree(outs command.Streams, view treeView) {
|
||||
if streamRedirected(outs.Out()) {
|
||||
_, _ = fmt.Fprintln(outs.Err(), "WARNING: This output is designed for human readability. For machine-readable output, please use --format.")
|
||||
}
|
||||
|
||||
out := tui.NewOutput(outs.Out())
|
||||
isTerm := out.IsTerminal()
|
||||
|
||||
@@ -569,17 +563,3 @@ 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
|
||||
}
|
||||
|
||||
@@ -157,6 +157,17 @@ func TestPrintImageTreeAnsiTty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintImageTreeNoWarningWhenRedirected(t *testing.T) {
|
||||
cli := test.NewFakeCli(nil)
|
||||
cli.Out().SetIsTerminal(false)
|
||||
cli.Err().SetIsTerminal(false)
|
||||
|
||||
printImageTree(cli, treeView{images: []topImage{}})
|
||||
|
||||
errOut := cli.ErrBuffer().String()
|
||||
assert.Check(t, !strings.Contains(errOut, "WARNING: This output is designed for human readability"), "stderr should not contain warning when output is redirected, got: %s", errOut)
|
||||
}
|
||||
|
||||
func TestPrintImageTreeGolden(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user