From c36e67d7b68601870936c9b0f7285a7f7c8544f3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 23 Aug 2025 16:18:09 +0200 Subject: [PATCH] cli/command/image: runPush: minor cleanups and linting issues - Remove redundant intermediate variables - Explicitly use an early return on error instead of combining with other checks. - Fix unhandled errors and combine defers - Remove outstanding TODO that unlikely will be addressed Signed-off-by: Sebastiaan van Stijn --- cli/command/image/push.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 3ec0d7d2c2..f81ebe0916 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -92,9 +92,11 @@ To push the complete multi-platform image, remove the --platform flag. } ref, err := reference.ParseNormalizedNamed(opts.remote) - switch { - case err != nil: + if err != nil { return err + } + + switch { case opts.all && !reference.IsNameOnly(ref): return errors.New("tag can't be used with --all-tags/-a") case !opts.all && reference.IsNameOnly(ref): @@ -113,34 +115,32 @@ To push the complete multi-platform image, remove the --platform flag. if err != nil { return err } - options := image.PushOptions{ + + responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), image.PushOptions{ All: opts.all, RegistryAuth: encodedAuth, PrivilegeFunc: nil, Platform: platform, - } - - responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), options) + }) if err != nil { return err } defer func() { + _ = responseBody.Close() for _, note := range notes { out.PrintNote(note) } }() - defer responseBody.Close() if !opts.untrusted { - // TODO pushTrustedReference currently doesn't respect `--quiet` return pushTrustedReference(ctx, dockerCli, indexInfo, ref, authConfig, responseBody) } if opts.quiet { err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux())) if err == nil { - fmt.Fprintln(dockerCli.Out(), ref.String()) + _, _ = fmt.Fprintln(dockerCli.Out(), ref.String()) } return err }