summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-30 20:57:02 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-30 20:57:52 -0400
commit457ee75d83e35c5dae397b8c001b74600e286eac (patch)
treec7191a4de75b13e9ee074770838aa32a5ca0b3c8 /cmd2/cmd2.py
parentad646aa05031121db825cb9a963452b7327f7bc7 (diff)
downloadcmd2-git-duplicate_subcommand.tar.gz
Fixed issue where instantiating more than one cmd2-based class which uses the @as_subcommand_toduplicate_subcommand
decorator resulted in duplicated help text in the base command the subcommands belong to.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py8
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, {})