The CLI.ManifestStore method is a shallow wrapper around manifeststore.NewStore and has no dependency on the CLI itself. However, due to its signature resulted in various dependencies becoming a dependency of the "command" package. Consequence of this was that cli-plugins, which need the cli/command package, would also get those dependencies. - This patch inlines the code to produce the store, skipping the wrapper. - Define a local interface for some tests where a dummy store was used. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package manifest
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/docker/cli/cli"
|
|
"github.com/docker/cli/cli/command"
|
|
manifeststore "github.com/docker/cli/cli/manifest/store"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
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 runRemove(cmd.Context(), newManifestStore(dockerCLI), args)
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runRemove(ctx context.Context, store manifeststore.Store, targets []string) error {
|
|
var errs []error
|
|
for _, target := range targets {
|
|
if ctx.Err() != nil {
|
|
return ctx.Err()
|
|
}
|
|
targetRef, err := normalizeReference(target)
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
continue
|
|
}
|
|
_, err = store.GetList(targetRef)
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
continue
|
|
}
|
|
err = store.Remove(targetRef)
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
}
|
|
}
|
|
return errors.Join(errs...)
|
|
}
|