cli/command/system: prettyPrintVersion: accept a plain io.Writer

We're only writing to a single stream, so may as well just let it
take an io.writer.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-22 09:09:40 +02:00
parent e06e758d5f
commit efd6e7b6e0
2 changed files with 8 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package system
import (
"context"
"io"
"runtime"
"sort"
"strconv"
@ -188,14 +189,14 @@ func runVersion(ctx context.Context, dockerCli command.Cli, opts *versionOptions
})
}
}
if err2 := prettyPrintVersion(dockerCli, vd, tmpl); err2 != nil && err == nil {
if err2 := prettyPrintVersion(dockerCli.Out(), vd, tmpl); err2 != nil && err == nil {
err = err2
}
return err
}
func prettyPrintVersion(dockerCli command.Cli, vd versionInfo, tmpl *template.Template) error {
t := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 1, ' ', 0)
func prettyPrintVersion(out io.Writer, vd versionInfo, tmpl *template.Template) error {
t := tabwriter.NewWriter(out, 20, 1, 1, ' ', 0)
err := tmpl.Execute(t, vd)
_, _ = t.Write([]byte("\n"))
_ = t.Flush()

View File

@ -1,6 +1,7 @@
package system
import (
"bytes"
"context"
"errors"
"io"
@ -125,10 +126,9 @@ func TestVersionFormat(t *testing.T) {
tmpl, err := newVersionTemplate(tc.format)
assert.NilError(t, err)
cli := test.NewFakeCli(&fakeClient{})
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
assert.Check(t, golden.String(cli.OutBuffer().String(), t.Name()+".golden"))
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
var out bytes.Buffer
assert.NilError(t, prettyPrintVersion(&out, vi, tmpl))
assert.Check(t, golden.String(out.String(), t.Name()+".golden"))
})
}
}