This replaces the visitAll recursive function with a test that verifies that the option is set for all commands and subcommands, so that it doesn't have to be modified at runtime. We currently still have to loop over all functions for the setValidateArgs call, but that can be looked at separately. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
50 lines
1.1 KiB
Go
50 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)
|
|
},
|
|
DisableFlagsInUseLine: true,
|
|
}
|
|
|
|
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...)
|
|
}
|