Skip to content

Commit ec00b85

Browse files
committed
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 <[email protected]> (cherry picked from commit c36e67d) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a69c591 commit ec00b85

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cli/command/image/push.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ To push the complete multi-platform image, remove the --platform flag.
100100
}
101101

102102
ref, err := reference.ParseNormalizedNamed(opts.remote)
103-
switch {
104-
case err != nil:
103+
if err != nil {
105104
return err
105+
}
106+
107+
switch {
106108
case opts.all && !reference.IsNameOnly(ref):
107109
return errors.New("tag can't be used with --all-tags/-a")
108110
case !opts.all && reference.IsNameOnly(ref):
@@ -121,34 +123,32 @@ To push the complete multi-platform image, remove the --platform flag.
121123
if err != nil {
122124
return err
123125
}
124-
options := image.PushOptions{
126+
127+
responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), image.PushOptions{
125128
All: opts.all,
126129
RegistryAuth: encodedAuth,
127130
PrivilegeFunc: nil,
128131
Platform: platform,
129-
}
130-
131-
responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
132+
})
132133
if err != nil {
133134
return err
134135
}
135136

136137
defer func() {
138+
_ = responseBody.Close()
137139
for _, note := range notes {
138140
out.PrintNote(note)
139141
}
140142
}()
141143

142-
defer responseBody.Close()
143144
if !opts.untrusted {
144-
// TODO pushTrustedReference currently doesn't respect `--quiet`
145145
return pushTrustedReference(ctx, dockerCli, indexInfo, ref, authConfig, responseBody)
146146
}
147147

148148
if opts.quiet {
149149
err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux()))
150150
if err == nil {
151-
fmt.Fprintln(dockerCli.Out(), ref.String())
151+
_, _ = fmt.Fprintln(dockerCli.Out(), ref.String())
152152
}
153153
return err
154154
}

0 commit comments

Comments
 (0)