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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-02-03 19:27:59 +01:00
parent f431f61568
commit 1fd9d0dd34
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -6,39 +6,43 @@ import (
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
manifeststore "github.com/docker/cli/cli/manifest/store"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func newRmManifestListCommand(dockerCli command.Cli) *cobra.Command { func newRmManifestListCommand(dockerCLI command.Cli) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "rm MANIFEST_LIST [MANIFEST_LIST...]", Use: "rm MANIFEST_LIST [MANIFEST_LIST...]",
Short: "Delete one or more manifest lists from local storage", Short: "Delete one or more manifest lists from local storage",
Args: cli.RequiresMinArgs(1), Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runRm(cmd.Context(), dockerCli, args) return runRemove(cmd.Context(), dockerCLI.ManifestStore(), args)
}, },
} }
return cmd 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 var errs []string
for _, target := range targets { for _, target := range targets {
targetRef, refErr := normalizeReference(target) if ctx.Err() != nil {
if refErr != nil { return ctx.Err()
errs = append(errs, refErr.Error()) }
targetRef, err := normalizeReference(target)
if err != nil {
errs = append(errs, err.Error())
continue continue
} }
_, searchErr := dockerCli.ManifestStore().GetList(targetRef) _, err = store.GetList(targetRef)
if searchErr != nil { if err != nil {
errs = append(errs, searchErr.Error()) errs = append(errs, err.Error())
continue continue
} }
rmErr := dockerCli.ManifestStore().Remove(targetRef) err = store.Remove(targetRef)
if rmErr != nil { if err != nil {
errs = append(errs, rmErr.Error()) errs = append(errs, err.Error())
} }
} }
if len(errs) > 0 { if len(errs) > 0 {