diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-05-28 13:27:23 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-06-11 11:01:13 +0200 |
commit | 7d71d24440afbf30689c53c2c69205072e4b029f (patch) | |
tree | 20ae3d75ac79b2e9cf5a237ce4582ecd6a508b9c /cmd/podman/parse | |
parent | 7f5aabb08389f9baee49bd76ab21f876e0bb70b9 (diff) | |
download | podman-7d71d24440afbf30689c53c2c69205072e4b029f.tar.gz podman-7d71d24440afbf30689c53c2c69205072e4b029f.tar.bz2 podman-7d71d24440afbf30689c53c2c69205072e4b029f.zip |
podman-pod{rm,start,stop}: support --pod-id-file
Support the `--pod-id-file` flag in the rm, start and stop pod commands.
This completes the already support flag in pod-create and is another
prerequisite for generating generic systemd unit files for pods.
Also add completions, docs and tests.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd/podman/parse')
-rw-r--r-- | cmd/podman/parse/common.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/cmd/podman/parse/common.go b/cmd/podman/parse/common.go index 13f425b6d..b3aa88da2 100644 --- a/cmd/podman/parse/common.go +++ b/cmd/podman/parse/common.go @@ -5,6 +5,10 @@ import ( "github.com/spf13/cobra" ) +// TODO: the two functions here are almost identical. It may be worth looking +// into generalizing the two a bit more and share code but time is scarce and +// we only live once. + // CheckAllLatestAndCIDFile checks that --all and --latest are used correctly. // If cidfile is set, also check for the --cidfile flag. func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error { @@ -55,3 +59,54 @@ func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool } return nil } + +// CheckAllLatestAndPodIDFile checks that --all and --latest are used correctly. +// If withIDFile is set, also check for the --pod-id-file flag. +func CheckAllLatestAndPodIDFile(c *cobra.Command, args []string, ignoreArgLen bool, withIDFile bool) error { + argLen := len(args) + if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil { + if !withIDFile { + return errors.New("unable to lookup values for 'latest' or 'all'") + } else if c.Flags().Lookup("pod-id-file") == nil { + return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'") + } + } + + specifiedAll, _ := c.Flags().GetBool("all") + specifiedLatest, _ := c.Flags().GetBool("latest") + specifiedPodIDFile := false + if pid, _ := c.Flags().GetStringArray("pod-id-file"); len(pid) > 0 { + specifiedPodIDFile = true + } + + if specifiedPodIDFile && (specifiedAll || specifiedLatest) { + return errors.Errorf("--all, --latest and --pod-id-file cannot be used together") + } else if specifiedAll && specifiedLatest { + return errors.Errorf("--all and --latest cannot be used together") + } + + if (argLen > 0) && specifiedAll { + return errors.Errorf("no arguments are needed with --all") + } + + if ignoreArgLen { + return nil + } + + if argLen > 0 { + if specifiedLatest { + return errors.Errorf("no arguments are needed with --latest") + } else if withIDFile && (specifiedLatest || specifiedPodIDFile) { + return errors.Errorf("no arguments are needed with --latest or --pod-id-file") + } + } + + if specifiedPodIDFile { + return nil + } + + if argLen < 1 && !specifiedAll && !specifiedLatest && !specifiedPodIDFile { + return errors.Errorf("you must provide at least one name or id") + } + return nil +} |