spiegel_podman/cmd/podman/manifest/remove.go
Jhon Honce 33944cefe7 [Techinal Debt] Cleanup ABI vs. Tunnel CLI commands
[NO TESTS NEEDED]

This commit cleans up two issues:
* Most commands support all EngineModes so default to that. Let
  outlayers declare their intent.
* Use cobra.Annotations to set supported EngineMode. This simplies
  instantiating commands as there is now one method to communicate a
  commands requirements rather than two.
* Combined aliased commands into one file
* Fixed aliased commands where Args field did not match
* Updated examples in README.md for writing commands
* Remove redundant flag DisableFlagsInUseLine in cobra.Command
  initialization.

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-05-27 11:40:43 -07:00

47 lines
1.3 KiB
Go

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
}