1
0
mirror of https://github.com/docker/cli.git synced 2026-10-29 23:02:33 +03:00

cli/command/image: handleAux: avoid using global var

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2026-06-04 15:03:12 +02:00
parent b50c369d8b
commit a11beec944
2 changed files with 7 additions and 11 deletions

View File

@@ -123,6 +123,7 @@ To push the complete multi-platform image, remove the --platform flag.
return err
}
var notes []string
defer func() {
_ = responseBody.Close()
for _, note := range notes {
@@ -131,18 +132,16 @@ To push the complete multi-platform image, remove the --platform flag.
}()
if opts.quiet {
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux(out)))
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux(&notes, out)))
if err == nil {
_, _ = fmt.Fprintln(dockerCli.Out(), ref.String())
}
return err
}
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux(out)))
return jsonstream.Display(ctx, responseBody, dockerCli.Out(), jsonstream.WithAuxCallback(handleAux(&notes, out)))
}
var notes []string
func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
func handleAux(notes *[]string, out tui.Output) func(jm jsonstream.JSONMessage) {
return func(jm jsonstream.JSONMessage) {
b := []byte(*jm.Aux)
@@ -153,7 +152,7 @@ func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
out.Color(aec.RedF).Apply(stripped.OriginalIndex.Digest.String()),
out.Color(aec.GreenF).Apply(stripped.SelectedManifest.Digest.String()),
)
notes = append(notes, note)
*notes = append(*notes, note)
}
var missing auxprogress.ContentMissing
@@ -166,7 +165,7 @@ func handleAux(out tui.Output) func(jm jsonstream.JSONMessage) {
Make sure you have all the referenced content and try again.
You can also push only a single platform specific manifest directly by specifying the platform you want to push with the --platform flag.`
notes = append(notes, note)
*notes = append(*notes, note)
}
}
}

View File

@@ -2,7 +2,6 @@ package image
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
@@ -109,10 +108,8 @@ func TestRunPushRespectsNoColorForAuxNotes(t *testing.T) {
},
})
cli.Out().SetIsTerminal(true)
notes = nil
t.Cleanup(func() { notes = nil })
err := runPush(context.Background(), cli, pushOptions{remote: "image:tag"})
err := runPush(t.Context(), cli, pushOptions{remote: "image:tag"})
assert.NilError(t, err)
out := cli.OutBuffer().String()