aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/manifest/remove.go
blob: c44c0991e7fd1e2616b3dac1899022e015089623 (plain)
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 (
	"context"
	"fmt"

	"github.com/containers/podman/v3/cmd/podman/common"
	"github.com/containers/podman/v3/cmd/podman/registry"
	"github.com/pkg/errors"
	"github.com/spf13/cobra"
)

var (
	removeCmd = &cobra.Command{
		Use:               "remove LIST IMAGE",
		Short:             "Remove an entry from a manifest list or image index",
		Long:              "Removes an image from a manifest list or image index.",
		RunE:              remove,
		ValidArgsFunction: common.AutocompleteImages,
		Example:           `podman manifest remove mylist:v1.11 sha256:15352d97781ffdf357bf3459c037be3efac4133dc9070c2dce7eca7c05c3e736`,
		Args:              cobra.ExactArgs(2),
	}
)

func init() {
	registry.Commands = append(registry.Commands, registry.CliCommand{
		Command: removeCmd,
		Parent:  manifestCmd,
	})
}

func remove(cmd *cobra.Command, args []string) error {
	listImageSpec := args[0]
	instanceSpec := args[1]
	if listImageSpec == "" {
		return errors.Errorf(`invalid image name "%s"`, listImageSpec)
	}
	if instanceSpec == "" {
		return errors.Errorf(`invalid image digest "%s"`, instanceSpec)
	}
	updatedListID, err := registry.ImageEngine().ManifestRemove(context.Background(), args)
	if err != nil {
		return errors.Wrapf(err, "error removing from manifest list %s", listImageSpec)
	}
	fmt.Printf("%s\n", updatedListID)
	return nil
}