]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/ceph_argparse: stop parsing when we run out of positional args
authorSage Weil <sage@newdream.net>
Sat, 22 May 2021 17:00:24 +0000 (13:00 -0400)
committerSage Weil <sage@newdream.net>
Tue, 1 Jun 2021 18:45:11 +0000 (14:45 -0400)
If we encouter an arg that is not a named flag/arg, and the next
item in the command description is non-positional, then raise an
'unexpected argument' exception.

Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/ceph_argparse.py

index e401ef0c3428bd3bc9d6e52393eab21f4f3f11d6..dd70156c97ec3fdebc0eef88bb98e87ea04336e1 100644 (file)
@@ -1196,6 +1196,10 @@ def validate(args: List[str],
                     store_arg(kwarg_desc, d)
                     continue
 
+            if not desc.positional:
+                # No more positional args!
+                raise ArgumentValid(f"Unexpected argument '{myarg}'")
+
             # Don't handle something as a positional argument if it
             # has a leading "--" unless it's a CephChoices (used for
             # "--yes-i-really-mean-it")