Skip to content

Commit 6cf2c02

Browse files
authored
Merge pull request #6187 from thaJeztah/container_unexport
cli/command/container: deprecate NewDiffFormat, DiffFormatWrite
2 parents 73604b8 + fdc90ca commit 6cf2c02

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

cli/command/container/diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func runDiff(ctx context.Context, dockerCLI command.Cli, containerID string) err
3333
}
3434
diffCtx := formatter.Context{
3535
Output: dockerCLI.Out(),
36-
Format: NewDiffFormat("{{.Type}} {{.Path}}"),
36+
Format: newDiffFormat("{{.Type}} {{.Path}}"),
3737
}
38-
return DiffFormatWrite(diffCtx, changes)
38+
return diffFormatWrite(diffCtx, changes)
3939
}

cli/command/container/formatter_diff.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,37 @@ const (
1313
)
1414

1515
// NewDiffFormat returns a format for use with a diff Context
16+
//
17+
// Deprecated: this function was only used internally and will be removed in the next release.
1618
func NewDiffFormat(source string) formatter.Format {
19+
return newDiffFormat(source)
20+
}
21+
22+
// newDiffFormat returns a format for use with a diff [formatter.Context].
23+
func newDiffFormat(source string) formatter.Format {
1724
if source == formatter.TableFormatKey {
1825
return defaultDiffTableFormat
1926
}
2027
return formatter.Format(source)
2128
}
2229

2330
// DiffFormatWrite writes formatted diff using the Context
24-
func DiffFormatWrite(ctx formatter.Context, changes []container.FilesystemChange) error {
25-
render := func(format func(subContext formatter.SubContext) error) error {
31+
//
32+
// Deprecated: this function was only used internally and will be removed in the next release.
33+
func DiffFormatWrite(fmtCtx formatter.Context, changes []container.FilesystemChange) error {
34+
return diffFormatWrite(fmtCtx, changes)
35+
}
36+
37+
// diffFormatWrite writes formatted diff using the [formatter.Context].
38+
func diffFormatWrite(fmtCtx formatter.Context, changes []container.FilesystemChange) error {
39+
return fmtCtx.Write(newDiffContext(), func(format func(subContext formatter.SubContext) error) error {
2640
for _, change := range changes {
2741
if err := format(&diffContext{c: change}); err != nil {
2842
return err
2943
}
3044
}
3145
return nil
32-
}
33-
return ctx.Write(newDiffContext(), render)
46+
})
3447
}
3548

3649
type diffContext struct {
@@ -39,12 +52,14 @@ type diffContext struct {
3952
}
4053

4154
func newDiffContext() *diffContext {
42-
diffCtx := diffContext{}
43-
diffCtx.Header = formatter.SubHeaderContext{
44-
"Type": changeTypeHeader,
45-
"Path": pathHeader,
55+
return &diffContext{
56+
HeaderContext: formatter.HeaderContext{
57+
Header: formatter.SubHeaderContext{
58+
"Type": changeTypeHeader,
59+
"Path": pathHeader,
60+
},
61+
},
4662
}
47-
return &diffCtx
4863
}
4964

5065
func (d *diffContext) MarshalJSON() ([]byte, error) {

cli/command/container/formatter_diff_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ func TestDiffContextFormatWrite(t *testing.T) {
1616
expected string
1717
}{
1818
{
19-
formatter.Context{Format: NewDiffFormat("table")},
19+
formatter.Context{Format: newDiffFormat("table")},
2020
`CHANGE TYPE PATH
2121
C /var/log/app.log
2222
A /usr/app/app.js
2323
D /usr/app/old_app.js
2424
`,
2525
},
2626
{
27-
formatter.Context{Format: NewDiffFormat("table {{.Path}}")},
27+
formatter.Context{Format: newDiffFormat("table {{.Path}}")},
2828
`PATH
2929
/var/log/app.log
3030
/usr/app/app.js
3131
/usr/app/old_app.js
3232
`,
3333
},
3434
{
35-
formatter.Context{Format: NewDiffFormat("{{.Type}}: {{.Path}}")},
35+
formatter.Context{Format: newDiffFormat("{{.Type}}: {{.Path}}")},
3636
`C: /var/log/app.log
3737
A: /usr/app/app.js
3838
D: /usr/app/old_app.js
@@ -50,7 +50,7 @@ D: /usr/app/old_app.js
5050
t.Run(string(tc.context.Format), func(t *testing.T) {
5151
out := bytes.NewBufferString("")
5252
tc.context.Output = out
53-
err := DiffFormatWrite(tc.context, diffs)
53+
err := diffFormatWrite(tc.context, diffs)
5454
if err != nil {
5555
assert.Error(t, err, tc.expected)
5656
} else {

0 commit comments

Comments
 (0)