diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-10-01 11:34:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 11:34:31 -0400 |
commit | c36569c890a9e3b2f25e7c232badd06fd0ca5af5 (patch) | |
tree | c7191a4de75b13e9ee074770838aa32a5ca0b3c8 /cmd2/cmd2.py | |
parent | ad646aa05031121db825cb9a963452b7327f7bc7 (diff) | |
parent | 457ee75d83e35c5dae397b8c001b74600e286eac (diff) | |
download | cmd2-git-c36569c890a9e3b2f25e7c232badd06fd0ca5af5.tar.gz |
Merge pull request #1005 from python-cmd2/duplicate_subcommand
Fixed duplicate help text of subcommands
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8810025a..ea4e01de 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -692,6 +692,14 @@ class Cmd(cmd.Cmd): for action in target_parser._actions: if isinstance(action, argparse._SubParsersAction): + # Temporary workaround for avoiding subcommand help text repeatedly getting added to + # action._choices_actions. Until we have instance-specific parser objects, we will remove + # any existing subcommand which has the same name before replacing it. This problem is + # exercised when more than one cmd2.Cmd-based object is created and the same subcommands + # get added each time. Argparse overwrites the previous subcommand but keeps growing the help + # text which is shown by running something like 'alias -h'. + action.remove_parser(subcommand_name) + # Get the kwargs for add_parser() add_parser_kwargs = getattr(method, constants.SUBCMD_ATTR_ADD_PARSER_KWARGS, {}) |