]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Limit a multivalued param that is followed by another required param
authorDavid Howells <dhowells@redhat.com>
Wed, 13 Aug 2014 12:57:50 +0000 (13:57 +0100)
committerDavid Howells <dhowells@redhat.com>
Wed, 13 Aug 2014 12:57:50 +0000 (13:57 +0100)
A multivalued parameter that is followed by another required parameter is
limited to a single value unless prefaced with its switch, eg:

pts adduser A B C D

B, C and D are group names and A is a user name, despite the user name field
taking multiple values.  In contrast in:

pts adduser -user A B -group C D

A and B are users and only C and D are groups.

Signed-off-by: David Howells <dhowells@redhat.com>
suite/argparse.py

index cfef3ba2776380349f27b4dc8082363f14758e5c..72580421afef2643185696056cf06a1a44fd69a7 100644 (file)
@@ -219,13 +219,19 @@ def parse_arguments(args, available_arguments, argument_size_limits,
             i = i + 1
 
             if match[2][1] == "m":
-                # All remaining arguments up to the next switch belong to this
-                while i < len(args):
-                    if args[i][0] == "-" and not args[i][1:].isnumeric():
-                        break
-                    params.append(args[i])
-                    i = i + 1
-                need_switch = True
+                # Multiple-value arguments that are not preceded by their
+                # switch are forced to be single-value if there's yet another
+                # required argument following.
+                if av < len(available_arguments) and available_arguments[av][2][0] == "r":
+                    pass
+                else:
+                    # All remaining arguments up to the next switch belong to this
+                    while i < len(args):
+                        if args[i][0] == "-" and not args[i][1:].isnumeric():
+                            break
+                        params.append(args[i])
+                        i = i + 1
+                    need_switch = True
 
         else:
             # Deal with tagged arguments