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>
This commit is contained in:
@ -66,7 +66,7 @@ func RunPull(ctx context.Context, dockerCLI command.Cli, opts PullOptions) error
|
||||
case !opts.all && reference.IsNameOnly(distributionRef):
|
||||
distributionRef = reference.TagNameOnly(distributionRef)
|
||||
if tagged, ok := distributionRef.(reference.Tagged); ok && !opts.quiet {
|
||||
fmt.Fprintf(dockerCLI.Out(), "Using default tag: %s\n", tagged.Tag())
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), "Using default tag:", tagged.Tag())
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,6 +88,6 @@ func RunPull(ctx context.Context, dockerCLI command.Cli, opts PullOptions) error
|
||||
}
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(dockerCLI.Out(), imgRefAndAuth.Reference().String())
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), imgRefAndAuth.Reference().String())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ To push the complete multi-platform image, remove the --platform flag.
|
||||
case !opts.all && reference.IsNameOnly(ref):
|
||||
ref = reference.TagNameOnly(ref)
|
||||
if tagged, ok := ref.(reference.Tagged); ok && !opts.quiet {
|
||||
_, _ = fmt.Fprintf(dockerCli.Out(), "Using default tag: %s\n", tagged.Tag())
|
||||
_, _ = fmt.Fprintln(dockerCli.Out(), "Using default tag:", tagged.Tag())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,8 +51,8 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||
return &cmd
|
||||
}
|
||||
|
||||
func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, images []string) error {
|
||||
client := dockerCli.Client()
|
||||
func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, images []string) error {
|
||||
apiClient := dockerCLI.Client()
|
||||
|
||||
options := image.RemoveOptions{
|
||||
Force: opts.force,
|
||||
@ -62,7 +62,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
|
||||
var errs []string
|
||||
fatalErr := false
|
||||
for _, img := range images {
|
||||
dels, err := client.ImageRemove(ctx, img, options)
|
||||
dels, err := apiClient.ImageRemove(ctx, img, options)
|
||||
if err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
fatalErr = true
|
||||
@ -71,9 +71,9 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
|
||||
} else {
|
||||
for _, del := range dels {
|
||||
if del.Deleted != "" {
|
||||
fmt.Fprintf(dockerCli.Out(), "Deleted: %s\n", del.Deleted)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), "Deleted:", del.Deleted)
|
||||
} else {
|
||||
fmt.Fprintf(dockerCli.Out(), "Untagged: %s\n", del.Untagged)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Out(), "Untagged:", del.Untagged)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,7 +84,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions, i
|
||||
if !opts.force || fatalErr {
|
||||
return errors.New(msg)
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Err(), msg)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
|
||||
if err := jsonstream.Display(ctx, in, ioStreams.Out()); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(ioStreams.Err(), "No tag specified, skipping trust metadata push")
|
||||
_, _ = fmt.Fprintln(ioStreams.Err(), "No tag specified, skipping trust metadata push")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
|
||||
return errors.Errorf("no targets found, provide a specific tag in order to sign it")
|
||||
}
|
||||
|
||||
fmt.Fprintln(ioStreams.Out(), "Signing and pushing trust metadata")
|
||||
_, _ = fmt.Fprintln(ioStreams.Out(), "Signing and pushing trust metadata")
|
||||
|
||||
repo, err := trust.GetNotaryRepository(ioStreams.In(), ioStreams.Out(), command.UserAgent(), repoInfo, &authConfig, "push", "pull")
|
||||
if err != nil {
|
||||
@ -133,7 +133,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
|
||||
if err := repo.Initialize([]string{rootKeyID}, data.CanonicalSnapshotRole); err != nil {
|
||||
return trust.NotaryError(repoInfo.Name.Name(), err)
|
||||
}
|
||||
fmt.Fprintf(ioStreams.Out(), "Finished initializing %q\n", repoInfo.Name.Name())
|
||||
_, _ = fmt.Fprintf(ioStreams.Out(), "Finished initializing %q\n", repoInfo.Name.Name())
|
||||
err = repo.AddTarget(target, data.CanonicalTargetsRole)
|
||||
case nil:
|
||||
// already initialized and we have successfully downloaded the latest metadata
|
||||
@ -151,7 +151,7 @@ func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoIn
|
||||
return trust.NotaryError(repoInfo.Name.Name(), err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(ioStreams.Out(), "Successfully signed %s:%s\n", repoInfo.Name.Name(), tag)
|
||||
_, _ = fmt.Fprintf(ioStreams.Out(), "Successfully signed %s:%s\n", repoInfo.Name.Name(), tag)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image
|
||||
if displayTag != "" {
|
||||
displayTag = ":" + displayTag
|
||||
}
|
||||
fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
|
||||
_, _ = fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
|
||||
|
||||
trustedRef, err := reference.WithDigest(reference.TrimNamed(ref), r.digest)
|
||||
if err != nil {
|
||||
@ -230,7 +230,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth)
|
||||
for _, tgt := range targets {
|
||||
t, err := convertTarget(tgt.Target)
|
||||
if err != nil {
|
||||
fmt.Fprintf(cli.Err(), "Skipping target for %q\n", reference.FamiliarName(ref))
|
||||
_, _ = fmt.Fprintf(cli.Err(), "Skipping target for %q\n", reference.FamiliarName(ref))
|
||||
continue
|
||||
}
|
||||
// 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
|
||||
familiarRef := reference.FamiliarString(ref)
|
||||
trustedFamiliarRef := reference.FamiliarString(trustedRef)
|
||||
|
||||
fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
|
||||
_, _ = fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
|
||||
|
||||
return cli.Client().ImageTag(ctx, trustedFamiliarRef, familiarRef)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user