diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-09-30 11:20:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 11:20:46 -0400 |
commit | ed7b9e5185fd14808aa26e61a26968b9753beee0 (patch) | |
tree | 18ef88b248f13c27c313ec64380894cd834f1531 /cmd2/cmd2.py | |
parent | 77444b71923fc9484017a6dc5a580db1ea8c7812 (diff) | |
parent | 980a7e47c90bafef7d5ea8b160680dd70d8ccea0 (diff) | |
download | cmd2-git-ed7b9e5185fd14808aa26e61a26968b9753beee0.tar.gz |
Merge pull request #1003 from python-cmd2/move_attach
Setting subcommand handler on attached_parser and not its parent parser
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 6e1a38ca..d1a26a2b 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -676,10 +676,6 @@ class Cmd(cmd.Cmd): raise CommandSetRegistrationError('Could not find argparser for command "{}" needed by subcommand: {}' .format(command_name, str(method))) - # Set the subcommand handler function - defaults = {constants.NS_ATTR_SUBCMD_HANDLER: method} - subcmd_parser.set_defaults(**defaults) - def find_subcommand(action: argparse.ArgumentParser, subcmd_names: List[str]) -> argparse.ArgumentParser: if not subcmd_names: return action @@ -720,6 +716,12 @@ class Cmd(cmd.Cmd): add_parser_kwargs['add_help'] = False attached_parser = action.add_parser(subcommand_name, **add_parser_kwargs) + + # Set the subcommand handler + defaults = {constants.NS_ATTR_SUBCMD_HANDLER: method} + attached_parser.set_defaults(**defaults) + + # Set what instance the handler is bound to setattr(attached_parser, constants.PARSER_ATTR_COMMANDSET, cmdset) break |