From 1fd9d0dd34a965eae92ed834ad71569b3a995466 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Feb 2025 19:27:59 +0100 Subject: [PATCH] cli/command/manifest: pass manifest-store and handle context - pass through the manifest-store, instead of the CLI as a whole - handle context cancellation - rename `runRm` to `runRemove` to align with other commands Signed-off-by: Sebastiaan van Stijn --- cli/command/manifest/rm.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cli/command/manifest/rm.go b/cli/command/manifest/rm.go index 2e2dc04624..ccb6044341 100644 --- a/cli/command/manifest/rm.go +++ b/cli/command/manifest/rm.go @@ -6,39 +6,43 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" + manifeststore "github.com/docker/cli/cli/manifest/store" "github.com/pkg/errors" "github.com/spf13/cobra" ) -func newRmManifestListCommand(dockerCli command.Cli) *cobra.Command { +func newRmManifestListCommand(dockerCLI command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "rm MANIFEST_LIST [MANIFEST_LIST...]", Short: "Delete one or more manifest lists from local storage", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - return runRm(cmd.Context(), dockerCli, args) + return runRemove(cmd.Context(), dockerCLI.ManifestStore(), args) }, } return cmd } -func runRm(_ context.Context, dockerCli command.Cli, targets []string) error { +func runRemove(ctx context.Context, store manifeststore.Store, targets []string) error { var errs []string for _, target := range targets { - targetRef, refErr := normalizeReference(target) - if refErr != nil { - errs = append(errs, refErr.Error()) + if ctx.Err() != nil { + return ctx.Err() + } + targetRef, err := normalizeReference(target) + if err != nil { + errs = append(errs, err.Error()) continue } - _, searchErr := dockerCli.ManifestStore().GetList(targetRef) - if searchErr != nil { - errs = append(errs, searchErr.Error()) + _, err = store.GetList(targetRef) + if err != nil { + errs = append(errs, err.Error()) continue } - rmErr := dockerCli.ManifestStore().Remove(targetRef) - if rmErr != nil { - errs = append(errs, rmErr.Error()) + err = store.Remove(targetRef) + if err != nil { + errs = append(errs, err.Error()) } } if len(errs) > 0 {