Fix aliased commands to actually work

The current aliased commands

podman container list

and

podman image list
podman image rm

Do not work properly.  The global storage options are broken.

This patch fixes this issue.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2019-03-02 07:14:28 -05:00
parent 4c618875f6
commit d231cfba92
8 changed files with 116 additions and 75 deletions

View File

@ -55,9 +55,6 @@ func getImageSubCommands() []*cobra.Command {
// Commands that the local client implements
func getContainerSubCommands() []*cobra.Command {
var _listSubCommand = _psCommand
_listSubCommand.Use = "list"
return []*cobra.Command{
_attachCommand,
_checkpointCommand,
@ -68,7 +65,6 @@ func getContainerSubCommands() []*cobra.Command {
_execCommand,
_exportCommand,
_killCommand,
&_listSubCommand,
_logsCommand,
_mountCommand,
_pauseCommand,

View File

@ -1,27 +1,49 @@
package main
import (
"strings"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/spf13/cobra"
)
var containerDescription = "Manage containers"
var containerCommand = cliconfig.PodmanCommand{
Command: &cobra.Command{
Use: "container",
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
},
}
var (
containerDescription = "Manage containers"
containerCommand = cliconfig.PodmanCommand{
Command: &cobra.Command{
Use: "container",
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
},
}
// Commands that are universally implemented.
var containerCommands = []*cobra.Command{
_containerExistsCommand,
_inspectCommand,
}
listSubCommand cliconfig.PsValues
_listSubCommand = &cobra.Command{
Use: strings.Replace(_psCommand.Use, "ps", "list", 1),
Short: _psCommand.Short,
Long: _psCommand.Long,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
listSubCommand.InputArgs = args
listSubCommand.GlobalFlags = MainGlobalOpts
return psCmd(&listSubCommand)
},
Example: strings.Replace(_psCommand.Example, "podman ps", "podman container list", -1),
}
// Commands that are universally implemented.
containerCommands = []*cobra.Command{
_containerExistsCommand,
_inspectCommand,
_listSubCommand,
}
)
func init() {
listSubCommand.Command = _listSubCommand
psInit(&listSubCommand)
containerCommand.AddCommand(containerCommands...)
containerCommand.AddCommand(getContainerSubCommands()...)
containerCommand.SetUsageTemplate(UsageTemplate())

View File

@ -16,14 +16,39 @@ var (
Long: imageDescription,
},
}
_imagesSubCommand = _imagesCommand
_rmSubCommand = _rmiCommand
imagesSubCommand cliconfig.ImagesValues
_imagesSubCommand = &cobra.Command{
Use: strings.Replace(_imagesCommand.Use, "images", "list", 1),
Short: _imagesCommand.Short,
Long: _imagesCommand.Long,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
imagesSubCommand.InputArgs = args
imagesSubCommand.GlobalFlags = MainGlobalOpts
return imagesCmd(&imagesSubCommand)
},
Example: strings.Replace(_imagesCommand.Example, "podman images", "podman image list", -1),
}
rmSubCommand cliconfig.RmiValues
_rmSubCommand = &cobra.Command{
Use: strings.Replace(_rmiCommand.Use, "rmi", "rm", 1),
Short: _rmiCommand.Short,
Long: _rmiCommand.Long,
RunE: func(cmd *cobra.Command, args []string) error {
rmSubCommand.InputArgs = args
rmSubCommand.GlobalFlags = MainGlobalOpts
return rmiCmd(&rmSubCommand)
},
Example: strings.Replace(_rmiCommand.Example, "podman rmi", "podman image rm", -1),
}
)
//imageSubCommands are implemented both in local and remote clients
var imageSubCommands = []*cobra.Command{
_buildCommand,
_historyCommand,
_imagesSubCommand,
_imageExistsCommand,
_importCommand,
_inspectCommand,
@ -31,23 +56,20 @@ var imageSubCommands = []*cobra.Command{
_pruneImagesCommand,
_pullCommand,
_pushCommand,
_rmSubCommand,
_saveCommand,
_tagCommand,
}
func init() {
rmSubCommand.Command = _rmSubCommand
rmiInit(&rmSubCommand)
imagesSubCommand.Command = _imagesSubCommand
imagesInit(&imagesSubCommand)
imageCommand.SetUsageTemplate(UsageTemplate())
imageCommand.AddCommand(imageSubCommands...)
imageCommand.AddCommand(getImageSubCommands()...)
// Setup of "images" to appear as "list"
_imagesSubCommand.Use = strings.Replace(_imagesSubCommand.Use, "images", "list", 1)
_imagesSubCommand.Aliases = []string{"ls"}
_imagesSubCommand.Example = strings.Replace(_imagesSubCommand.Example, "podman images", "podman image list", -1)
imageCommand.AddCommand(&_imagesSubCommand)
// It makes no sense to keep 'podman images rmi'; just use 'rm'
_rmSubCommand.Use = strings.Replace(_rmSubCommand.Use, "rmi", "rm", 1)
_rmSubCommand.Example = strings.Replace(_rmSubCommand.Example, "podman rmi", "podman image rm", -1)
imageCommand.AddCommand(&_rmSubCommand)
}

View File

@ -102,24 +102,28 @@ var (
}
)
func init() {
imagesCommand.Command = &_imagesCommand
imagesCommand.SetUsageTemplate(UsageTemplate())
func imagesInit(command *cliconfig.ImagesValues) {
command.SetUsageTemplate(UsageTemplate())
flags := imagesCommand.Flags()
flags.BoolVarP(&imagesCommand.All, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&imagesCommand.Digests, "digests", false, "Show digests")
flags.StringSliceVarP(&imagesCommand.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringVar(&imagesCommand.Format, "format", "", "Change the output format to JSON or a Go template")
flags.BoolVarP(&imagesCommand.Noheading, "noheading", "n", false, "Do not print column headings")
flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&command.Digests, "digests", false, "Show digests")
flags.StringSliceVarP(&command.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringVar(&command.Format, "format", "", "Change the output format to JSON or a Go template")
flags.BoolVarP(&command.Noheading, "noheading", "n", false, "Do not print column headings")
// TODO Need to learn how to deal with second name being a string instead of a char.
// This needs to be "no-trunc, notruncate"
flags.BoolVar(&imagesCommand.NoTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVarP(&imagesCommand.Quiet, "quiet", "q", false, "Display only image IDs")
flags.StringVar(&imagesCommand.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
flags.BoolVar(&command.NoTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVarP(&command.Quiet, "quiet", "q", false, "Display only image IDs")
flags.StringVar(&command.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
}
func init() {
imagesCommand.Command = &_imagesCommand
imagesInit(&imagesCommand)
}
func imagesCmd(c *cliconfig.ImagesValues) error {
var (
filterFuncs []imagefilters.ResultFilter

View File

@ -173,27 +173,31 @@ var (
}
)
func init() {
psCommand.Command = &_psCommand
psCommand.SetUsageTemplate(UsageTemplate())
flags := psCommand.Flags()
flags.BoolVarP(&psCommand.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&psCommand.Filter, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&psCommand.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&psCommand.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVarP(&psCommand.Latest, "latest", "l", false, "Show the latest container created (all states)")
flags.BoolVar(&psCommand.Namespace, "namespace", false, "Display namespace information")
flags.BoolVar(&psCommand.Namespace, "ns", false, "Display namespace information")
flags.BoolVar(&psCommand.NoTrunct, "no-trunc", false, "Display the extended information")
flags.BoolVarP(&psCommand.Pod, "pod", "p", false, "Print the ID and name of the pod the containers are associated with")
flags.BoolVarP(&psCommand.Quiet, "quiet", "q", false, "Print the numeric IDs of the containers only")
flags.BoolVarP(&psCommand.Size, "size", "s", false, "Display the total file sizes")
flags.StringVar(&psCommand.Sort, "sort", "created", "Sort output by command, created, id, image, names, runningfor, size, or status")
flags.BoolVar(&psCommand.Sync, "sync", false, "Sync container state with OCI runtime")
func psInit(command *cliconfig.PsValues) {
command.SetUsageTemplate(UsageTemplate())
flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&command.Filter, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&command.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&command.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVarP(&command.Latest, "latest", "l", false, "Show the latest container created (all states)")
flags.BoolVar(&command.Namespace, "namespace", false, "Display namespace information")
flags.BoolVar(&command.Namespace, "ns", false, "Display namespace information")
flags.BoolVar(&command.NoTrunct, "no-trunc", false, "Display the extended information")
flags.BoolVarP(&command.Pod, "pod", "p", false, "Print the ID and name of the pod the containers are associated with")
flags.BoolVarP(&command.Quiet, "quiet", "q", false, "Print the numeric IDs of the containers only")
flags.BoolVarP(&command.Size, "size", "s", false, "Display the total file sizes")
flags.StringVar(&command.Sort, "sort", "created", "Sort output by command, created, id, image, names, runningfor, size, or status")
flags.BoolVar(&command.Sync, "sync", false, "Sync container state with OCI runtime")
markFlagHiddenForRemoteClient("latest", flags)
}
func init() {
psCommand.Command = &_psCommand
psInit(&psCommand)
}
func psCmd(c *cliconfig.PsValues) error {
if c.Bool("trace") {
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")

View File

@ -29,12 +29,16 @@ var (
}
)
func rmiInit(command *cliconfig.RmiValues) {
command.SetUsageTemplate(UsageTemplate())
flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Remove all images")
flags.BoolVarP(&command.Force, "force", "f", false, "Force Removal of the image")
}
func init() {
rmiCommand.Command = &_rmiCommand
rmiCommand.SetUsageTemplate(UsageTemplate())
flags := rmiCommand.Flags()
flags.BoolVarP(&rmiCommand.All, "all", "a", false, "Remove all images")
flags.BoolVarP(&rmiCommand.Force, "force", "f", false, "Force Removal of the image")
rmiInit(&rmiCommand)
}
func rmiCmd(c *cliconfig.RmiValues) error {

View File

@ -88,17 +88,6 @@ var _ = Describe("Podman rm", func() {
Expect(len(images.OutputToStringArray())).To(Equal(0))
})
It("podman container image prune unused images", func() {
prune := podmanTest.Podman([]string{"container", "image", "prune", "-a"})
prune.WaitWithDefaultTimeout()
Expect(prune.ExitCode()).To(Equal(0))
images := podmanTest.Podman([]string{"image", "list", "-a"})
images.WaitWithDefaultTimeout()
// all images are unused, so they all should be deleted!
Expect(len(images.OutputToStringArray())).To(Equal(0))
})
It("podman system image prune unused images", func() {
SkipIfRemote()
podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")

View File

@ -70,7 +70,7 @@ var _ = Describe("Podman run", func() {
It("podman container run a container based on on a short name with localhost", func() {
podmanTest.RestoreArtifact(nginx)
tag := podmanTest.Podman([]string{"container", "tag", nginx, "localhost/libpod/alpine_nginx:latest"})
tag := podmanTest.Podman([]string{"image", "tag", nginx, "localhost/libpod/alpine_nginx:latest"})
tag.WaitWithDefaultTimeout()
rmi := podmanTest.Podman([]string{"image", "rm", nginx})