Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 0 additions & 2 deletions cli/command/image/testdata/list-command-ambiguous.golden
Original file line number Diff line number Diff line change
@@ -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"?
20 changes: 0 additions & 20 deletions cli/command/image/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -233,10 +231,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()

Expand Down Expand Up @@ -564,17 +558,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
}
11 changes: 11 additions & 0 deletions cli/command/image/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ func TestPrintImageTreeAnsiTty(t *testing.T) {
}
}

func TestPrintImageTreeNoWarningWhenRedirected(t *testing.T) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General software engineering guidelines: don't bother with negative unit tests because theoretically there's no end of tests you could write to verify something isn't happening.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I already had a branch prepared to removed it, because it's covered by the other tests already. We were in process of getting things ready for a v29.5.0 release candidate, and I wanted to make sure it didn't miss the boat.

Normally I would've amended the PR, but new restrictions now require paperwork and sign-offs from higher-up when doing so 😭 so I'll just fix it in a follow-up.

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
Expand Down
Loading