From: David Howells Date: Wed, 13 Aug 2014 12:57:50 +0000 (+0100) Subject: Limit a multivalued param that is followed by another required param X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f98ffaf7bcd8c993a6f5555aea6bf834949ca33c;p=users%2Fdhowells%2Fkafs-utils.git Limit a multivalued param that is followed by another required param 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 --- diff --git a/suite/argparse.py b/suite/argparse.py index cfef3ba..7258042 100644 --- a/suite/argparse.py +++ b/suite/argparse.py @@ -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