mirror of
https://github.com/containers/podman.git
synced 2025-08-02 01:09:21 +08:00
Add checkAllAndLatest() function
The check about the --all and --latest option is used and repeated and some commands. Factor it out and put it into common. Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:

committed by
Adrian Reber

parent
95c93577cd
commit
9d9493e41a
@ -89,6 +89,21 @@ func validateFlags(c *cli.Context, flags []cli.Flag) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkAllAndLatest checks that --all and --latest are used correctly
|
||||
func checkAllAndLatest(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")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getContext returns a non-nil, empty context
|
||||
func getContext() context.Context {
|
||||
return context.TODO()
|
||||
|
Reference in New Issue
Block a user