| 2305 | |
| 2306 | # function to convert arg_strings into positional actions |
| 2307 | def consume_positionals(start_index): |
| 2308 | # match as many Positionals as possible |
| 2309 | match_partial = self._match_arguments_partial |
| 2310 | selected_pattern = arg_strings_pattern[start_index:] |
| 2311 | arg_counts = match_partial(positionals, selected_pattern) |
| 2312 | |
| 2313 | # slice off the appropriate arg strings for each Positional |
| 2314 | # and add the Positional and its args to the list |
| 2315 | for action, arg_count in zip(positionals, arg_counts): |
| 2316 | args = arg_strings[start_index: start_index + arg_count] |
| 2317 | # Strip out the first '--' if it is not in REMAINDER arg. |
| 2318 | if action.nargs == PARSER: |
| 2319 | if arg_strings_pattern[start_index] == '-': |
| 2320 | assert args[0] == '--' |
| 2321 | args.remove('--') |
| 2322 | elif action.nargs != REMAINDER: |
| 2323 | if (arg_strings_pattern.find('-', start_index, |
| 2324 | start_index + arg_count) >= 0): |
| 2325 | args.remove('--') |
| 2326 | start_index += arg_count |
| 2327 | if args and action.deprecated and action.dest not in warned: |
| 2328 | self._warning(_("argument '%(argument_name)s' is deprecated") % |
| 2329 | {'argument_name': action.dest}) |
| 2330 | warned.add(action.dest) |
| 2331 | take_action(action, args) |
| 2332 | |
| 2333 | # slice off the Positionals that we just parsed and return the |
| 2334 | # index at which the Positionals' string args stopped |
| 2335 | positionals[:] = positionals[len(arg_counts):] |
| 2336 | return start_index |
| 2337 | |
| 2338 | # consume Positionals and Optionals alternately, until we have |
| 2339 | # passed the last option string |