Skip to content

Commit 15cf4fa

Browse files
committed
cli/command/image: deprecate NewHistoryFormat, HistoryWrite
It's part of the presentation logic of the cli, and only used internally. We can consider providing utilities for these, but better as part of separate packages. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent e3903a1 commit 15cf4fa

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

‎cli/command/image/formatter_history.go‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ const (
2020
)
2121

2222
// NewHistoryFormat returns a format for rendering an HistoryContext
23+
//
24+
// Deprecated: this function was only used internally and will be removed in the next release.
2325
func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format {
26+
return newHistoryFormat(source, quiet, human)
27+
}
28+
29+
// newHistoryFormat returns a format for rendering a historyContext.
30+
func newHistoryFormat(source string, quiet bool, human bool) formatter.Format {
2431
if source == formatter.TableFormatKey {
2532
switch {
2633
case quiet:
@@ -36,10 +43,17 @@ func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format {
3643
}
3744

3845
// HistoryWrite writes the context
39-
func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
46+
//
47+
// Deprecated: this function was only used internally and will be removed in the next release.
48+
func HistoryWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
49+
return historyWrite(fmtCtx, human, histories)
50+
}
51+
52+
// historyWrite writes the context
53+
func historyWrite(fmtCtx formatter.Context, human bool, histories []image.HistoryResponseItem) error {
4054
render := func(format func(subContext formatter.SubContext) error) error {
4155
for _, history := range histories {
42-
historyCtx := &historyContext{trunc: ctx.Trunc, h: history, human: human}
56+
historyCtx := &historyContext{trunc: fmtCtx.Trunc, h: history, human: human}
4357
if err := format(historyCtx); err != nil {
4458
return err
4559
}
@@ -55,7 +69,7 @@ func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryRe
5569
"Size": formatter.SizeHeader,
5670
"Comment": commentHeader,
5771
}
58-
return ctx.Write(historyCtx, render)
72+
return fmtCtx.Write(historyCtx, render)
5973
}
6074

6175
type historyContext struct {

‎cli/command/image/formatter_history_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ imageID6 17 years ago /bin/bash echo 183MB
237237
}{
238238
{
239239
formatter.Context{
240-
Format: NewHistoryFormat("table", false, true),
240+
Format: newHistoryFormat("table", false, true),
241241
Trunc: true,
242242
Output: out,
243243
},
244244
expectedTrunc,
245245
},
246246
{
247247
formatter.Context{
248-
Format: NewHistoryFormat("table", false, true),
248+
Format: newHistoryFormat("table", false, true),
249249
Trunc: false,
250250
Output: out,
251251
},
@@ -255,7 +255,7 @@ imageID6 17 years ago /bin/bash echo 183MB
255255

256256
for _, tc := range cases {
257257
t.Run(string(tc.context.Format), func(t *testing.T) {
258-
err := HistoryWrite(tc.context, true, histories)
258+
err := historyWrite(tc.context, true, histories)
259259
assert.NilError(t, err)
260260
assert.Equal(t, out.String(), tc.expected)
261261
// Clean buffer

‎cli/command/image/history.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func runHistory(ctx context.Context, dockerCli command.Cli, opts historyOptions)
7777

7878
historyCtx := formatter.Context{
7979
Output: dockerCli.Out(),
80-
Format: NewHistoryFormat(format, opts.quiet, opts.human),
80+
Format: newHistoryFormat(format, opts.quiet, opts.human),
8181
Trunc: !opts.noTrunc,
8282
}
83-
return HistoryWrite(historyCtx, opts.human, history)
83+
return historyWrite(historyCtx, opts.human, history)
8484
}

0 commit comments

Comments
 (0)