Skip to content

Commit c8f27b0

Browse files
committed
cli/command/image: minor cleanups: use Println, rename vars
- use Println to print newline instead of custom format - use apiClient instead of client for the API client to prevent shadowing imports. - use dockerCLI with Go's standard camelCase casing. - suppress some errors to make my IDE and linters happier Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent a0ca41e commit c8f27b0

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

cli/command/image/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func RunPull(ctx context.Context, dockerCLI command.Cli, opts PullOptions) error
6666
case !opts.all && reference.IsNameOnly(distributionRef):
6767
distributionRef = reference.TagNameOnly(distributionRef)
6868
if tagged, ok := distributionRef.(reference.Tagged); ok && !opts.quiet {
69-
fmt.Fprintf(dockerCLI.Out(), "Using default tag: %s\n", tagged.Tag())
69+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Using default tag:", tagged.Tag())
7070
}
7171
}
7272

@@ -88,6 +88,6 @@ func RunPull(ctx context.Context, dockerCLI command.Cli, opts PullOptions) error
8888
}
8989
return err
9090
}
91-
fmt.Fprintln(dockerCLI.Out(), imgRefAndAuth.Reference().String())
91+
_, _ = fmt.Fprintln(dockerCLI.Out(), imgRefAndAuth.Reference().String())
9292
return nil
9393
}

cli/command/image/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ To push the complete multi-platform image, remove the --platform flag.
101101
case !opts.all && reference.IsNameOnly(ref):
102102
ref = reference.TagNameOnly(ref)
103103
if tagged, ok := ref.(reference.Tagged); ok && !opts.quiet {
104-
_, _ = fmt.Fprintf(dockerCli.Out(), "Using default tag: %s\n", tagged.Tag())
104+
_, _ = fmt.Fprintln(dockerCli.Out(), "Using default tag:", tagged.Tag())
105105
}
106106
}
107107

cli/command/image/remove.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
5151
return &cmd
5252
}
5353

54-
func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, images []string) error {
55-
client := dockerCli.Client()
54+
func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string) error {
55+
apiClient := dockerCLI.Client()
5656

5757
options := image.RemoveOptions{
5858
Force: opts.force,
@@ -62,7 +62,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
6262
var errs []string
6363
fatalErr := false
6464
for _, img := range images {
65-
dels, err := client.ImageRemove(ctx, img, options)
65+
dels, err := apiClient.ImageRemove(ctx, img, options)
6666
if err != nil {
6767
if !errdefs.IsNotFound(err) {
6868
fatalErr = true
@@ -71,9 +71,9 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
7171
} else {
7272
for _, del := range dels {
7373
if del.Deleted != "" {
74-
fmt.Fprintf(dockerCli.Out(), "Deleted: %s\n", del.Deleted)
74+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Deleted:", del.Deleted)
7575
} else {
76-
fmt.Fprintf(dockerCli.Out(), "Untagged: %s\n", del.Untagged)
76+
_, _ = fmt.Fprintln(dockerCLI.Out(), "Untagged:", del.Untagged)
7777
}
7878
}
7979
}
@@ -84,7 +84,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
8484
if !opts.force || fatalErr {
8585
return errors.New(msg)
8686
}
87-
fmt.Fprintln(dockerCli.Err(), msg)
87+
_, _ = fmt.Fprintln(dockerCLI.Err(), msg)
8888
}
8989
return nil
9090
}

cli/command/image/trust.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
8787
if err := jsonstream.Display(ctx, in, ioStreams.Out()); err != nil {
8888
return err
8989
}
90-
fmt.Fprintln(ioStreams.Err(), "No tag specified, skipping trust metadata push")
90+
_, _ = fmt.Fprintln(ioStreams.Err(), "No tag specified, skipping trust metadata push")
9191
return nil
9292
}
9393

@@ -103,7 +103,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
103103
return errors.Errorf("no targets found, provide a specific tag in order to sign it")
104104
}
105105

106-
fmt.Fprintln(ioStreams.Out(), "Signing and pushing trust metadata")
106+
_, _ = fmt.Fprintln(ioStreams.Out(), "Signing and pushing trust metadata")
107107

108108
repo, err := trust.GetNotaryRepository(ioStreams.In(), ioStreams.Out(), command.UserAgent(), repoInfo, &authConfig, "push", "pull")
109109
if err != nil {
@@ -133,7 +133,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
133133
if err := repo.Initialize([]string{rootKeyID}, data.CanonicalSnapshotRole); err != nil {
134134
return trust.NotaryError(repoInfo.Name.Name(), err)
135135
}
136-
fmt.Fprintf(ioStreams.Out(), "Finished initializing %q\n", repoInfo.Name.Name())
136+
_, _ = fmt.Fprintf(ioStreams.Out(), "Finished initializing %q\n", repoInfo.Name.Name())
137137
err = repo.AddTarget(target, data.CanonicalTargetsRole)
138138
case nil:
139139
// already initialized and we have successfully downloaded the latest metadata
@@ -151,7 +151,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
151151
return trust.NotaryError(repoInfo.Name.Name(), err)
152152
}
153153

154-
fmt.Fprintf(ioStreams.Out(), "Successfully signed %s:%s\n", repoInfo.Name.Name(), tag)
154+
_, _ = fmt.Fprintf(ioStreams.Out(), "Successfully signed %s:%s\n", repoInfo.Name.Name(), tag)
155155
return nil
156156
}
157157

@@ -181,7 +181,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
181181
if displayTag != "" {
182182
displayTag = ":" + displayTag
183183
}
184-
fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
184+
_, _ = fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
185185

186186
trustedRef, err := reference.WithDigest(reference.TrimNamed(ref), r.digest)
187187
if err != nil {
@@ -230,7 +230,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
230230
for _, tgt := range targets {
231231
t, err := convertTarget(tgt.Target)
232232
if err != nil {
233-
fmt.Fprintf(cli.Err(), "Skipping target for %q\n", reference.FamiliarName(ref))
233+
_, _ = fmt.Fprintf(cli.Err(), "Skipping target for %q\n", reference.FamiliarName(ref))
234234
continue
235235
}
236236
// Only list tags in the top level targets role or the releases delegation role - ignore
@@ -332,7 +332,7 @@ func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canon
332332
familiarRef := reference.FamiliarString(ref)
333333
trustedFamiliarRef := reference.FamiliarString(trustedRef)
334334

335-
fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
335+
_, _ = fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
336336

337337
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
338338
}

0 commit comments

Comments
 (0)