summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
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, {})