2020-09-14 21:56:35 -04:00
|
|
|
package manifest
|
|
|
|
|
|
|
|
import (
|
2023-09-09 18:27:44 -04:00
|
|
|
"context"
|
2020-09-14 21:56:35 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"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 {
|
2023-09-09 18:27:44 -04:00
|
|
|
return runRm(cmd.Context(), dockerCli, args)
|
2020-09-14 21:56:35 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2023-09-09 18:27:44 -04:00
|
|
|
func runRm(_ context.Context, dockerCli command.Cli, targets []string) error {
|
2020-09-14 21:56:35 -04:00
|
|
|
var errs []string
|
|
|
|
for _, target := range targets {
|
|
|
|
targetRef, refErr := normalizeReference(target)
|
|
|
|
if refErr != nil {
|
|
|
|
errs = append(errs, refErr.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, searchErr := dockerCli.ManifestStore().GetList(targetRef)
|
|
|
|
if searchErr != nil {
|
|
|
|
errs = append(errs, searchErr.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
rmErr := dockerCli.ManifestStore().Remove(targetRef)
|
|
|
|
if rmErr != nil {
|
|
|
|
errs = append(errs, rmErr.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(errs) > 0 {
|
|
|
|
return errors.New(strings.Join(errs, "\n"))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|