Skip to content

Commit d861b78

Browse files
committed
cli/command/checkpoint: deprecate NewFormat, FormatWrite
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 15cf4fa commit d861b78

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

‎cli/command/checkpoint/formatter.go‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@ const (
1111
)
1212

1313
// NewFormat returns a format for use with a checkpoint Context
14+
//
15+
// Deprecated: this function was only used internally and will be removed in the next release.
1416
func NewFormat(source string) formatter.Format {
17+
return newFormat(source)
18+
}
19+
20+
// newFormat returns a format for use with a checkpointContext.
21+
func newFormat(source string) formatter.Format {
1522
if source == formatter.TableFormatKey {
1623
return defaultCheckpointFormat
1724
}
1825
return formatter.Format(source)
1926
}
2027

2128
// FormatWrite writes formatted checkpoints using the Context
22-
func FormatWrite(ctx formatter.Context, checkpoints []checkpoint.Summary) error {
29+
//
30+
// Deprecated: this function was only used internally and will be removed in the next release.
31+
func FormatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
32+
return formatWrite(fmtCtx, checkpoints)
33+
}
34+
35+
// formatWrite writes formatted checkpoints using the Context
36+
func formatWrite(fmtCtx formatter.Context, checkpoints []checkpoint.Summary) error {
2337
render := func(format func(subContext formatter.SubContext) error) error {
2438
for _, cp := range checkpoints {
2539
if err := format(&checkpointContext{c: cp}); err != nil {
@@ -28,7 +42,7 @@ func FormatWrite(ctx formatter.Context, checkpoints []checkpoint.Summary) error
2842
}
2943
return nil
3044
}
31-
return ctx.Write(newCheckpointContext(), render)
45+
return fmtCtx.Write(newCheckpointContext(), render)
3246
}
3347

3448
type checkpointContext struct {

‎cli/command/checkpoint/formatter_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ func TestCheckpointContextFormatWrite(t *testing.T) {
1515
expected string
1616
}{
1717
{
18-
formatter.Context{Format: NewFormat(defaultCheckpointFormat)},
18+
formatter.Context{Format: newFormat(defaultCheckpointFormat)},
1919
`CHECKPOINT NAME
2020
checkpoint-1
2121
checkpoint-2
2222
checkpoint-3
2323
`,
2424
},
2525
{
26-
formatter.Context{Format: NewFormat("{{.Name}}")},
26+
formatter.Context{Format: newFormat("{{.Name}}")},
2727
`checkpoint-1
2828
checkpoint-2
2929
checkpoint-3
3030
`,
3131
},
3232
{
33-
formatter.Context{Format: NewFormat("{{.Name}}:")},
33+
formatter.Context{Format: newFormat("{{.Name}}:")},
3434
`checkpoint-1:
3535
checkpoint-2:
3636
checkpoint-3:
@@ -41,7 +41,7 @@ checkpoint-3:
4141
for _, testcase := range cases {
4242
out := bytes.NewBufferString("")
4343
testcase.context.Output = out
44-
err := FormatWrite(testcase.context, []checkpoint.Summary{
44+
err := formatWrite(testcase.context, []checkpoint.Summary{
4545
{Name: "checkpoint-1"},
4646
{Name: "checkpoint-2"},
4747
{Name: "checkpoint-3"},

‎cli/command/checkpoint/list.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func runList(ctx context.Context, dockerCli command.Cli, container string, opts
4545

4646
cpCtx := formatter.Context{
4747
Output: dockerCli.Out(),
48-
Format: NewFormat(formatter.TableFormatKey),
48+
Format: newFormat(formatter.TableFormatKey),
4949
}
50-
return FormatWrite(cpCtx, checkpoints)
50+
return formatWrite(cpCtx, checkpoints)
5151
}

0 commit comments

Comments
 (0)