mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
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:
@ -55,9 +55,6 @@ func getImageSubCommands() []*cobra.Command {
|
|||||||
// Commands that the local client implements
|
// Commands that the local client implements
|
||||||
func getContainerSubCommands() []*cobra.Command {
|
func getContainerSubCommands() []*cobra.Command {
|
||||||
|
|
||||||
var _listSubCommand = _psCommand
|
|
||||||
_listSubCommand.Use = "list"
|
|
||||||
|
|
||||||
return []*cobra.Command{
|
return []*cobra.Command{
|
||||||
_attachCommand,
|
_attachCommand,
|
||||||
_checkpointCommand,
|
_checkpointCommand,
|
||||||
@ -68,7 +65,6 @@ func getContainerSubCommands() []*cobra.Command {
|
|||||||
_execCommand,
|
_execCommand,
|
||||||
_exportCommand,
|
_exportCommand,
|
||||||
_killCommand,
|
_killCommand,
|
||||||
&_listSubCommand,
|
|
||||||
_logsCommand,
|
_logsCommand,
|
||||||
_mountCommand,
|
_mountCommand,
|
||||||
_pauseCommand,
|
_pauseCommand,
|
||||||
|
@ -1,27 +1,49 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var containerDescription = "Manage containers"
|
var (
|
||||||
var containerCommand = cliconfig.PodmanCommand{
|
containerDescription = "Manage containers"
|
||||||
Command: &cobra.Command{
|
containerCommand = cliconfig.PodmanCommand{
|
||||||
Use: "container",
|
Command: &cobra.Command{
|
||||||
Short: "Manage Containers",
|
Use: "container",
|
||||||
Long: containerDescription,
|
Short: "Manage Containers",
|
||||||
TraverseChildren: true,
|
Long: containerDescription,
|
||||||
},
|
TraverseChildren: true,
|
||||||
}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Commands that are universally implemented.
|
listSubCommand cliconfig.PsValues
|
||||||
var containerCommands = []*cobra.Command{
|
_listSubCommand = &cobra.Command{
|
||||||
_containerExistsCommand,
|
Use: strings.Replace(_psCommand.Use, "ps", "list", 1),
|
||||||
_inspectCommand,
|
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() {
|
func init() {
|
||||||
|
listSubCommand.Command = _listSubCommand
|
||||||
|
psInit(&listSubCommand)
|
||||||
|
|
||||||
containerCommand.AddCommand(containerCommands...)
|
containerCommand.AddCommand(containerCommands...)
|
||||||
containerCommand.AddCommand(getContainerSubCommands()...)
|
containerCommand.AddCommand(getContainerSubCommands()...)
|
||||||
containerCommand.SetUsageTemplate(UsageTemplate())
|
containerCommand.SetUsageTemplate(UsageTemplate())
|
||||||
|
@ -16,14 +16,39 @@ var (
|
|||||||
Long: imageDescription,
|
Long: imageDescription,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_imagesSubCommand = _imagesCommand
|
imagesSubCommand cliconfig.ImagesValues
|
||||||
_rmSubCommand = _rmiCommand
|
_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
|
//imageSubCommands are implemented both in local and remote clients
|
||||||
var imageSubCommands = []*cobra.Command{
|
var imageSubCommands = []*cobra.Command{
|
||||||
_buildCommand,
|
_buildCommand,
|
||||||
_historyCommand,
|
_historyCommand,
|
||||||
|
_imagesSubCommand,
|
||||||
_imageExistsCommand,
|
_imageExistsCommand,
|
||||||
_importCommand,
|
_importCommand,
|
||||||
_inspectCommand,
|
_inspectCommand,
|
||||||
@ -31,23 +56,20 @@ var imageSubCommands = []*cobra.Command{
|
|||||||
_pruneImagesCommand,
|
_pruneImagesCommand,
|
||||||
_pullCommand,
|
_pullCommand,
|
||||||
_pushCommand,
|
_pushCommand,
|
||||||
|
_rmSubCommand,
|
||||||
_saveCommand,
|
_saveCommand,
|
||||||
_tagCommand,
|
_tagCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
rmSubCommand.Command = _rmSubCommand
|
||||||
|
rmiInit(&rmSubCommand)
|
||||||
|
|
||||||
|
imagesSubCommand.Command = _imagesSubCommand
|
||||||
|
imagesInit(&imagesSubCommand)
|
||||||
|
|
||||||
imageCommand.SetUsageTemplate(UsageTemplate())
|
imageCommand.SetUsageTemplate(UsageTemplate())
|
||||||
imageCommand.AddCommand(imageSubCommands...)
|
imageCommand.AddCommand(imageSubCommands...)
|
||||||
imageCommand.AddCommand(getImageSubCommands()...)
|
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)
|
|
||||||
}
|
}
|
||||||
|
@ -102,24 +102,28 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func imagesInit(command *cliconfig.ImagesValues) {
|
||||||
imagesCommand.Command = &_imagesCommand
|
command.SetUsageTemplate(UsageTemplate())
|
||||||
imagesCommand.SetUsageTemplate(UsageTemplate())
|
|
||||||
|
|
||||||
flags := imagesCommand.Flags()
|
flags := command.Flags()
|
||||||
flags.BoolVarP(&imagesCommand.All, "all", "a", false, "Show all images (default hides intermediate images)")
|
flags.BoolVarP(&command.All, "all", "a", false, "Show all images (default hides intermediate images)")
|
||||||
flags.BoolVar(&imagesCommand.Digests, "digests", false, "Show digests")
|
flags.BoolVar(&command.Digests, "digests", false, "Show digests")
|
||||||
flags.StringSliceVarP(&imagesCommand.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
|
flags.StringSliceVarP(&command.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.StringVar(&command.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.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.
|
// TODO Need to learn how to deal with second name being a string instead of a char.
|
||||||
// This needs to be "no-trunc, notruncate"
|
// This needs to be "no-trunc, notruncate"
|
||||||
flags.BoolVar(&imagesCommand.NoTrunc, "no-trunc", false, "Do not truncate output")
|
flags.BoolVar(&command.NoTrunc, "no-trunc", false, "Do not truncate output")
|
||||||
flags.BoolVarP(&imagesCommand.Quiet, "quiet", "q", false, "Display only image IDs")
|
flags.BoolVarP(&command.Quiet, "quiet", "q", false, "Display only image IDs")
|
||||||
flags.StringVar(&imagesCommand.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
|
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 {
|
func imagesCmd(c *cliconfig.ImagesValues) error {
|
||||||
var (
|
var (
|
||||||
filterFuncs []imagefilters.ResultFilter
|
filterFuncs []imagefilters.ResultFilter
|
||||||
|
@ -173,27 +173,31 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func psInit(command *cliconfig.PsValues) {
|
||||||
psCommand.Command = &_psCommand
|
command.SetUsageTemplate(UsageTemplate())
|
||||||
psCommand.SetUsageTemplate(UsageTemplate())
|
flags := command.Flags()
|
||||||
flags := psCommand.Flags()
|
flags.BoolVarP(&command.All, "all", "a", false, "Show all the containers, default is only running containers")
|
||||||
flags.BoolVarP(&psCommand.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.StringSliceVarP(&psCommand.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.StringVar(&psCommand.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.IntVarP(&psCommand.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.BoolVarP(&psCommand.Latest, "latest", "l", false, "Show the latest container created (all states)")
|
flags.BoolVar(&command.Namespace, "namespace", false, "Display namespace information")
|
||||||
flags.BoolVar(&psCommand.Namespace, "namespace", false, "Display namespace information")
|
flags.BoolVar(&command.Namespace, "ns", false, "Display namespace information")
|
||||||
flags.BoolVar(&psCommand.Namespace, "ns", false, "Display namespace information")
|
flags.BoolVar(&command.NoTrunct, "no-trunc", false, "Display the extended information")
|
||||||
flags.BoolVar(&psCommand.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(&psCommand.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(&psCommand.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.BoolVarP(&psCommand.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.StringVar(&psCommand.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")
|
||||||
flags.BoolVar(&psCommand.Sync, "sync", false, "Sync container state with OCI runtime")
|
|
||||||
|
|
||||||
markFlagHiddenForRemoteClient("latest", flags)
|
markFlagHiddenForRemoteClient("latest", flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
psCommand.Command = &_psCommand
|
||||||
|
psInit(&psCommand)
|
||||||
|
}
|
||||||
|
|
||||||
func psCmd(c *cliconfig.PsValues) error {
|
func psCmd(c *cliconfig.PsValues) error {
|
||||||
if c.Bool("trace") {
|
if c.Bool("trace") {
|
||||||
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")
|
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")
|
||||||
|
@ -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() {
|
func init() {
|
||||||
rmiCommand.Command = &_rmiCommand
|
rmiCommand.Command = &_rmiCommand
|
||||||
rmiCommand.SetUsageTemplate(UsageTemplate())
|
rmiInit(&rmiCommand)
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func rmiCmd(c *cliconfig.RmiValues) error {
|
func rmiCmd(c *cliconfig.RmiValues) error {
|
||||||
|
@ -88,17 +88,6 @@ var _ = Describe("Podman rm", func() {
|
|||||||
Expect(len(images.OutputToStringArray())).To(Equal(0))
|
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() {
|
It("podman system image prune unused images", func() {
|
||||||
SkipIfRemote()
|
SkipIfRemote()
|
||||||
podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")
|
podmanTest.BuildImage(pruneImage, "alpine_bash:latest", "true")
|
||||||
|
@ -70,7 +70,7 @@ var _ = Describe("Podman run", func() {
|
|||||||
|
|
||||||
It("podman container run a container based on on a short name with localhost", func() {
|
It("podman container run a container based on on a short name with localhost", func() {
|
||||||
podmanTest.RestoreArtifact(nginx)
|
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()
|
tag.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
rmi := podmanTest.Podman([]string{"image", "rm", nginx})
|
rmi := podmanTest.Podman([]string{"image", "rm", nginx})
|
||||||
|
Reference in New Issue
Block a user