-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
rm.go
47 lines (42 loc) · 1.07 KB
/
rm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package manifest
import (
"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 {
return runRm(dockerCli, args)
},
}
return cmd
}
func runRm(dockerCli command.Cli, targets []string) error {
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
}