_process_args(largs : [string], rargs : [string], values : Values) Process command-line arguments and populate 'values', consuming options and arguments from 'rargs'. If 'allow_interspersed_args' is false, stop at the first
(self, largs, rargs, values)
| 1395 | return (values, args) |
| 1396 | |
| 1397 | def _process_args(self, largs, rargs, values): |
| 1398 | """_process_args(largs : [string], |
| 1399 | rargs : [string], |
| 1400 | values : Values) |
| 1401 | |
| 1402 | Process command-line arguments and populate 'values', consuming |
| 1403 | options and arguments from 'rargs'. If 'allow_interspersed_args' is |
| 1404 | false, stop at the first non-option argument. If true, accumulate any |
| 1405 | interspersed non-option arguments in 'largs'. |
| 1406 | """ |
| 1407 | while rargs: |
| 1408 | arg = rargs[0] |
| 1409 | # We handle bare "--" explicitly, and bare "-" is handled by the |
| 1410 | # standard arg handler since the short arg case ensures that the |
| 1411 | # len of the opt string is greater than 1. |
| 1412 | if arg == "--": |
| 1413 | del rargs[0] |
| 1414 | return |
| 1415 | elif arg[0:2] == "--": |
| 1416 | # process a single long option (possibly with value(s)) |
| 1417 | self._process_long_opt(rargs, values) |
| 1418 | elif arg[:1] == "-" and len(arg) > 1: |
| 1419 | # process a cluster of short options (possibly with |
| 1420 | # value(s) for the last one only) |
| 1421 | self._process_short_opts(rargs, values) |
| 1422 | elif self.allow_interspersed_args: |
| 1423 | largs.append(arg) |
| 1424 | del rargs[0] |
| 1425 | else: |
| 1426 | return # stop now, leave this arg in rargs |
| 1427 | |
| 1428 | # Say this is the original argument list: |
| 1429 | # [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)] |
| 1430 | # ^ |
| 1431 | # (we are about to process arg(i)). |
| 1432 | # |
| 1433 | # Then rargs is [arg(i), ..., arg(N-1)] and largs is a *subset* of |
| 1434 | # [arg0, ..., arg(i-1)] (any options and their arguments will have |
| 1435 | # been removed from largs). |
| 1436 | # |
| 1437 | # The while loop will usually consume 1 or more arguments per pass. |
| 1438 | # If it consumes 1 (eg. arg is an option that takes no arguments), |
| 1439 | # then after _process_arg() is done the situation is: |
| 1440 | # |
| 1441 | # largs = subset of [arg0, ..., arg(i)] |
| 1442 | # rargs = [arg(i+1), ..., arg(N-1)] |
| 1443 | # |
| 1444 | # If allow_interspersed_args is false, largs will always be |
| 1445 | # *empty* -- still a subset of [arg0, ..., arg(i-1)], but |
| 1446 | # not a very interesting subset! |
| 1447 | |
| 1448 | def _match_long_opt(self, opt): |
| 1449 | """_match_long_opt(opt : string) -> string |
no test coverage detected