cli/command/plugin: runCreate: minor cleanup

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-01-08 12:48:15 +01:00
parent 667ece32cf
commit bf2dae22de
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"os" "os"
"path/filepath" "path/filepath"
@ -35,7 +34,7 @@ func validateConfig(path string) error {
m := types.PluginConfig{} m := types.PluginConfig{}
err = json.NewDecoder(dt).Decode(&m) err = json.NewDecoder(dt).Decode(&m)
dt.Close() _ = dt.Close()
return err return err
} }
@ -87,11 +86,6 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
} }
func runCreate(ctx context.Context, dockerCli command.Cli, options pluginCreateOptions) error { func runCreate(ctx context.Context, dockerCli command.Cli, options pluginCreateOptions) error {
var (
createCtx io.ReadCloser
err error
)
if err := validateTag(options.repoName); err != nil { if err := validateTag(options.repoName); err != nil {
return err return err
} }
@ -111,17 +105,17 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options pluginCreateO
compression = archive.Gzip compression = archive.Gzip
} }
createCtx, err = archive.TarWithOptions(absContextDir, &archive.TarOptions{ createCtx, err := archive.TarWithOptions(absContextDir, &archive.TarOptions{
Compression: compression, Compression: compression,
}) })
if err != nil { if err != nil {
return err return err
} }
createOptions := types.PluginCreateOptions{RepoName: options.repoName} err = dockerCli.Client().PluginCreate(ctx, createCtx, types.PluginCreateOptions{RepoName: options.repoName})
if err = dockerCli.Client().PluginCreate(ctx, createCtx, createOptions); err != nil { if err != nil {
return err return err
} }
fmt.Fprintln(dockerCli.Out(), options.repoName) _, _ = fmt.Fprintln(dockerCli.Out(), options.repoName)
return nil return nil
} }