From a11beec9441929d3be522b87edf09e07d650d263 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 Jun 2026 15:03:12 +0200 Subject: [PATCH] cli/command/image: handleAux: avoid using global var Signed-off-by: Sebastiaan van Stijn --- cli/command/image/push.go | 13 ++++++------- cli/command/image/push_test.go | 5 +---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index acd0fa17f633..78ee48d664b0 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -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(¬es, 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(¬es, 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) } } } diff --git a/cli/command/image/push_test.go b/cli/command/image/push_test.go index 0ffed25428d3..e0e0195e6a28 100644 --- a/cli/command/image/push_test.go +++ b/cli/command/image/push_test.go @@ -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()