Skip to content

Commit efd6e7b

Browse files
committed
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 <[email protected]>
1 parent e06e758 commit efd6e7b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

cli/command/system/version.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package system
22

33
import (
44
"context"
5+
"io"
56
"runtime"
67
"sort"
78
"strconv"
@@ -188,14 +189,14 @@ func runVersion(ctx context.Context, dockerCli command.Cli, opts *versionOptions
188189
})
189190
}
190191
}
191-
if err2 := prettyPrintVersion(dockerCli, vd, tmpl); err2 != nil && err == nil {
192+
if err2 := prettyPrintVersion(dockerCli.Out(), vd, tmpl); err2 != nil && err == nil {
192193
err = err2
193194
}
194195
return err
195196
}
196197

197-
func prettyPrintVersion(dockerCli command.Cli, vd versionInfo, tmpl *template.Template) error {
198-
t := tabwriter.NewWriter(dockerCli.Out(), 20, 1, 1, ' ', 0)
198+
func prettyPrintVersion(out io.Writer, vd versionInfo, tmpl *template.Template) error {
199+
t := tabwriter.NewWriter(out, 20, 1, 1, ' ', 0)
199200
err := tmpl.Execute(t, vd)
200201
_, _ = t.Write([]byte("\n"))
201202
_ = t.Flush()

cli/command/system/version_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package system
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"io"
@@ -125,10 +126,9 @@ func TestVersionFormat(t *testing.T) {
125126
tmpl, err := newVersionTemplate(tc.format)
126127
assert.NilError(t, err)
127128

128-
cli := test.NewFakeCli(&fakeClient{})
129-
assert.NilError(t, prettyPrintVersion(cli, vi, tmpl))
130-
assert.Check(t, golden.String(cli.OutBuffer().String(), t.Name()+".golden"))
131-
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
129+
var out bytes.Buffer
130+
assert.NilError(t, prettyPrintVersion(&out, vi, tmpl))
131+
assert.Check(t, golden.String(out.String(), t.Name()+".golden"))
132132
})
133133
}
134134
}

0 commit comments

Comments
 (0)