diff options
author | Adrian Reber <areber@redhat.com> | 2018-10-16 12:04:45 +0000 |
---|---|---|
committer | Adrian Reber <adrian@lisas.de> | 2018-10-23 17:01:30 +0200 |
commit | fea37b387c746471177f90f15b04d7735a88e621 (patch) | |
tree | 77b4bf6ae101c001ed543e44daa7b5cbec497404 /cmd | |
parent | 215cf7b8984f687a79ce6055e350ee3e75d81b79 (diff) | |
download | podman-fea37b387c746471177f90f15b04d7735a88e621.tar.gz podman-fea37b387c746471177f90f15b04d7735a88e621.tar.bz2 podman-fea37b387c746471177f90f15b04d7735a88e621.zip |
Use the new checkAllAndLatest() function
Instead of duplicating the same code in multiple commands this uses the
newly added function checkAllAndLatest() instead.
Signed-off-by: Adrian Reber <areber@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/cleanup.go | 19 | ||||
-rw-r--r-- | cmd/podman/kill.go | 16 | ||||
-rw-r--r-- | cmd/podman/rm.go | 10 | ||||
-rw-r--r-- | cmd/podman/stop.go | 14 | ||||
-rw-r--r-- | cmd/podman/utils.go | 11 |
5 files changed, 21 insertions, 49 deletions
diff --git a/cmd/podman/cleanup.go b/cmd/podman/cleanup.go index 3fd150783..1d8b2fbec 100644 --- a/cmd/podman/cleanup.go +++ b/cmd/podman/cleanup.go @@ -44,33 +44,25 @@ func cleanupCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - args := c.Args() - - ctx := getContext() + if err := checkAllAndLatest(c); err != nil { + return err + } var lastError error var cleanupContainers []*libpod.Container if c.Bool("all") { - if c.Bool("lastest") { - return errors.New("--all and --latest cannot be used together") - } - if len(args) != 0 { - return errors.New("--all and explicit container IDs cannot be used together") - } cleanupContainers, err = runtime.GetContainers() if err != nil { return errors.Wrapf(err, "unable to get container list") } } else if c.Bool("latest") { - if len(args) != 0 { - return errors.New("--latest and explicit container IDs cannot be used together") - } lastCtr, err := runtime.GetLatestContainer() if err != nil { return errors.Wrapf(err, "unable to get latest container") } cleanupContainers = append(cleanupContainers, lastCtr) } else { + args := c.Args() for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { @@ -81,6 +73,9 @@ func cleanupCmd(c *cli.Context) error { cleanupContainers = append(cleanupContainers, container) } } + + ctx := getContext() + for _, ctr := range cleanupContainers { if err = ctr.Cleanup(ctx); err != nil { if lastError != nil { diff --git a/cmd/podman/kill.go b/cmd/podman/kill.go index 56dd170b5..37b24a923 100644 --- a/cmd/podman/kill.go +++ b/cmd/podman/kill.go @@ -41,19 +41,10 @@ var ( // killCmd kills one or more containers with a signal func killCmd(c *cli.Context) error { - args := c.Args() - if (!c.Bool("all") && !c.Bool("latest")) && len(args) == 0 { - return errors.Errorf("you must specify one or more containers to kill") - } - if (c.Bool("all") || c.Bool("latest")) && len(args) > 0 { - return errors.Errorf("you cannot specify any containers to kill with --latest or --all") - } - if c.Bool("all") && c.Bool("latest") { - return errors.Errorf("--all and --latest cannot be used together") - } - if len(args) < 1 && !c.Bool("all") && !c.Bool("latest") { - return errors.Errorf("you must provide at least one container name or id") + if err := checkAllAndLatest(c); err != nil { + return err } + if err := validateFlags(c, killFlags); err != nil { return err } @@ -96,6 +87,7 @@ func killCmd(c *cli.Context) error { } containers = append(containers, lastCtr) } else { + args := c.Args() for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index 38b1546ff..847ea642d 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -63,13 +63,8 @@ func rmCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - args := c.Args() - if c.Bool("latest") && c.Bool("all") { - return errors.Errorf("--all and --latest cannot be used together") - } - - if len(args) == 0 && !c.Bool("all") && !c.Bool("latest") { - return errors.Errorf("specify one or more containers to remove") + if err := checkAllAndLatest(c); err != nil { + return err } if c.Bool("all") { @@ -84,6 +79,7 @@ func rmCmd(c *cli.Context) error { } delContainers = append(delContainers, lastCtr) } else { + args := c.Args() for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { diff --git a/cmd/podman/stop.go b/cmd/podman/stop.go index ff0b36bf1..f5c0fca85 100644 --- a/cmd/podman/stop.go +++ b/cmd/podman/stop.go @@ -44,16 +44,11 @@ var ( ) func stopCmd(c *cli.Context) error { - args := c.Args() - if (c.Bool("all") || c.Bool("latest")) && len(args) > 0 { - return errors.Errorf("no arguments are needed with --all or --latest") - } - if c.Bool("all") && c.Bool("latest") { - return errors.Errorf("--all and --latest cannot be used together") - } - if len(args) < 1 && !c.Bool("all") && !c.Bool("latest") { - return errors.Errorf("you must provide at least one container name or id") + + if err := checkAllAndLatest(c); err != nil { + return err } + if err := validateFlags(c, stopFlags); err != nil { return err } @@ -86,6 +81,7 @@ func stopCmd(c *cli.Context) error { } containers = append(containers, lastCtr) } else { + args := c.Args() for _, i := range args { container, err := runtime.LookupContainer(i) if err != nil { diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go index b193cf889..f9971fd88 100644 --- a/cmd/podman/utils.go +++ b/cmd/podman/utils.go @@ -160,15 +160,8 @@ func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) { } func checkMutuallyExclusiveFlags(c *cli.Context) error { - argLen := len(c.Args()) - if (c.Bool("all") || c.Bool("latest")) && argLen > 0 { - return errors.Errorf("no arguments are needed with --all or --latest") - } - if c.Bool("all") && c.Bool("latest") { - return errors.Errorf("--all and --latest cannot be used together") - } - if argLen < 1 && !c.Bool("all") && !c.Bool("latest") { - return errors.Errorf("you must provide at least one pod name or id") + if err := checkAllAndLatest(c); err != nil { + return err } if err := validateFlags(c, startFlags); err != nil { return err |