Skip to content

Commit 02dee5c

Browse files
Fix: Remove inconsistent human readability warning from docker images
Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
1 parent d5ed037 commit 02dee5c

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

cli/command/image/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,6 @@ func printAmbiguousHint(stdErr io.Writer, matchName string) {
211211
"save",
212212
"tag":
213213

214-
_, _ = fmt.Fprintf(stdErr, "\nNo images found matching %q: did you mean \"docker image %[1]s\"?\n", matchName)
214+
_, _ = fmt.Fprintf(stdErr, "No images found matching %q: did you mean \"docker image %[1]s\"?\n", matchName)
215215
}
216216
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
WARNING: This output is designed for human readability. For machine-readable output, please use --format.
2-
31
No images found matching "ls": did you mean "docker image ls"?

cli/command/image/tree.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ package image
66
import (
77
"context"
88
"fmt"
9-
"os"
109
"slices"
1110
"strings"
1211

1312
"github.com/containerd/platforms"
1413
"github.com/docker/cli/cli/command"
1514
"github.com/docker/cli/cli/command/formatter"
16-
"github.com/docker/cli/cli/streams"
1715
"github.com/docker/cli/internal/tui"
1816
"github.com/docker/go-units"
1917
imagetypes "github.com/moby/moby/api/types/image"
@@ -233,10 +231,6 @@ func getPossibleChips(view treeView) (chips []imageChip) {
233231
}
234232

235233
func printImageTree(outs command.Streams, view treeView) {
236-
if streamRedirected(outs.Out()) {
237-
_, _ = fmt.Fprintln(outs.Err(), "WARNING: This output is designed for human readability. For machine-readable output, please use --format.")
238-
}
239-
240234
out := tui.NewOutput(outs.Out())
241235
isTerm := out.IsTerminal()
242236

@@ -564,17 +558,3 @@ func widestFirstColumnValue(headers []imgColumn, images []topImage) int {
564558
}
565559
return width
566560
}
567-
568-
func streamRedirected(s *streams.Out) bool {
569-
fd := s.FD()
570-
if os.Stdout.Fd() != fd {
571-
return true
572-
}
573-
574-
fi, err := os.Stdout.Stat()
575-
if err != nil {
576-
return true
577-
}
578-
579-
return fi.Mode()&os.ModeCharDevice == 0
580-
}

cli/command/image/tree_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ func TestPrintImageTreeAnsiTty(t *testing.T) {
157157
}
158158
}
159159

160+
func TestPrintImageTreeNoWarningWhenRedirected(t *testing.T) {
161+
cli := test.NewFakeCli(nil)
162+
cli.Out().SetIsTerminal(false)
163+
cli.Err().SetIsTerminal(false)
164+
165+
printImageTree(cli, treeView{images: []topImage{}})
166+
167+
errOut := cli.ErrBuffer().String()
168+
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)
169+
}
170+
160171
func TestPrintImageTreeGolden(t *testing.T) {
161172
testCases := []struct {
162173
name string

0 commit comments

Comments
 (0)