diff -r 9ea84f006892 Lib/argparse.py --- a/Lib/argparse.py Wed May 01 15:15:50 2013 +0200 +++ b/Lib/argparse.py Fri Sep 27 23:15:33 2013 -0700 @@ -2064,6 +2064,20 @@ # return the list of arg string counts return result + def _get_nested_action(self, arg_string): + # recursively seek arg_string in subparsers + if self._subparsers is not None: + for action in self._subparsers._actions: + if isinstance(action, _SubParsersAction): + for parser in action._name_parser_map.values(): + if arg_string in parser._option_string_actions: + return parser._option_string_actions[arg_string] + else: + sub_action = parser._get_nested_action(arg_string) + if sub_action is not None: + return sub_action + return None + def _parse_optional(self, arg_string): # if it's an empty string, it was meant to be a positional if not arg_string: @@ -2078,6 +2092,11 @@ action = self._option_string_actions[arg_string] return action, arg_string, None + if getattr(self, 'scan', None): + if self._get_nested_action(arg_string): + # action is found in subparser; return as at end + return None, arg_string, None + # if it's just a single character, it was meant to be positional if len(arg_string) == 1: return None