diff options
author | Ed Santiago <santiago@redhat.com> | 2019-02-26 12:28:35 -0700 |
---|---|---|
committer | Ed Santiago <santiago@redhat.com> | 2019-02-27 14:20:29 -0700 |
commit | 9934507d74c97bccb753b04873eb74652600b6ff (patch) | |
tree | e4519b72b661fd87759f7544bef1dd4a87852c3b /cmd/podman/common.go | |
parent | 4e553cfd468c06ae45a88c51c57137dc4607ffe4 (diff) | |
download | podman-9934507d74c97bccb753b04873eb74652600b6ff.tar.gz podman-9934507d74c97bccb753b04873eb74652600b6ff.tar.bz2 podman-9934507d74c97bccb753b04873eb74652600b6ff.zip |
Command-line input validation: reject unused args
Several podman commands accept no subcommands. Some
of those were not actually checking, though, which
could lead to user confusion. Added validation where
missing; and, refactored to minimize duplication.
(Side note: I decided against using cobra.NoArgs
because its error message, "unknown command",
misleadingly implies that there are known ones).
Also added validation to varlink
Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'cmd/podman/common.go')
-rw-r--r-- | cmd/podman/common.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go index e297f3921..1fb06cf91 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -59,6 +59,14 @@ func checkAllAndLatest(c *cobra.Command, args []string, ignoreArgLen bool) error return nil } +// noSubArgs checks that there are no further positional parameters +func noSubArgs(c *cobra.Command, args []string) error { + if len(args) > 0 { + return errors.Errorf("`%s` takes no arguments", c.CommandPath()) + } + return nil +} + // getAllOrLatestContainers tries to return the correct list of containers // depending if --all, --latest or <container-id> is used. // It requires the Context (c) and the Runtime (runtime). As different |