diff options
author | baude <bbaude@redhat.com> | 2018-01-02 16:29:43 -0600 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-08 19:12:17 +0000 |
commit | 7b08aa78e4ede4c54fda6cd9917bb62e18d0d634 (patch) | |
tree | 1c480d9dfb8db3268dc3fdcca827792278a3ae47 /cmd/podman/kill.go | |
parent | 6baf6e461de6e560cc48d35239e7c392bec4481c (diff) | |
download | podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.gz podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.tar.bz2 podman-7b08aa78e4ede4c54fda6cd9917bb62e18d0d634.zip |
Shortcut for most recent container
It is desirable to have a shortcut for the most
recently created container. We can now use "**latest"
to represent the most recent container instead of its
container ID or name. For example:
Signed-off-by: baude <bbaude@redhat.com>
Closes: #179
Approved by: baude
Diffstat (limited to 'cmd/podman/kill.go')
-rw-r--r-- | cmd/podman/kill.go | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/cmd/podman/kill.go b/cmd/podman/kill.go index 776c7ef20..c24e68c54 100644 --- a/cmd/podman/kill.go +++ b/cmd/podman/kill.go @@ -1,10 +1,10 @@ package main import ( - "fmt" "os" "syscall" + "fmt" "github.com/docker/docker/pkg/signal" "github.com/pkg/errors" "github.com/urfave/cli" @@ -17,24 +17,29 @@ var ( Usage: "Signal to send to the container", Value: "KILL", }, + LatestFlag, } killDescription = "The main process inside each container specified will be sent SIGKILL, or any signal specified with option --signal." killCommand = cli.Command{ - Name: "kill", - Usage: "Kill one or more running containers with a specific signal", - Description: killDescription, - Flags: killFlags, - Action: killCmd, - ArgsUsage: "[CONTAINER_NAME_OR_ID]", + Name: "kill", + Usage: "Kill one or more running containers with a specific signal", + Description: killDescription, + Flags: killFlags, + Action: killCmd, + ArgsUsage: "[CONTAINER_NAME_OR_ID]", + UseShortOptionHandling: true, } ) // killCmd kills one or more containers with a signal func killCmd(c *cli.Context) error { args := c.Args() - if len(args) == 0 { + if len(args) == 0 && !c.Bool("latest") { return errors.Errorf("specify one or more containers to kill") } + if len(args) > 0 && c.Bool("latest") { + return errors.Errorf("you cannot specific any containers to kill with --latest") + } if err := validateFlags(c, killFlags); err != nil { return err } @@ -56,8 +61,16 @@ func killCmd(c *cli.Context) error { killSignal = uint(sysSignal) } + if c.Bool("latest") { + latestCtr, err := runtime.GetLatestContainer() + if err != nil { + return errors.Wrapf(err, "unable to get latest container") + } + args = append(args, latestCtr.ID()) + } + var lastError error - for _, container := range c.Args() { + for _, container := range args { ctr, err := runtime.LookupContainer(container) if err != nil { if lastError != nil { |