@@ -550,6 +550,7 @@ def _match_argument_wrapper(self, action, arg_strings_pattern) -> int:
550550# Patch argparse._SubParsersAction to add remove_parser function
551551############################################################################################################
552552
553+ # noinspection PyPep8Naming
553554def _SubParsersAction_remove_parser (self , name : str ):
554555 """
555556 Removes a sub-parser from a sub-parsers group
@@ -558,23 +559,23 @@ def _SubParsersAction_remove_parser(self, name: str):
558559 class so cmd2 can remove subcommands from a parser.
559560
560561 :param self: instance of the _SubParsersAction being edited
561- :param name: name of the sub-parser to remove
562+ :param name: name of the subcommand for the sub-parser to remove
562563 """
564+ # Remove this subcommand from its base command's help text
563565 for choice_action in self ._choices_actions :
564566 if choice_action .dest == name :
565567 self ._choices_actions .remove (choice_action )
566568 break
567569
568- subparser = self ._name_parser_map [name ]
569- to_remove = []
570- for name , parser in self ._name_parser_map .items ():
571- if parser is subparser :
572- to_remove .append (name )
573- for name in to_remove :
574- del self ._name_parser_map [name ]
575-
576- if name in self .choices :
577- del self .choices [name ]
570+ # Remove this subcommand and all its aliases from the base command
571+ subparser = self ._name_parser_map .get (name )
572+ if subparser is not None :
573+ to_remove = []
574+ for cur_name , cur_parser in self ._name_parser_map .items ():
575+ if cur_parser is subparser :
576+ to_remove .append (cur_name )
577+ for cur_name in to_remove :
578+ del self ._name_parser_map [cur_name ]
578579
579580
580581# noinspection PyProtectedMember
@@ -733,6 +734,7 @@ def _format_action_invocation(self, action) -> str:
733734 return ', ' .join (action .option_strings ) + ' ' + args_string
734735 # End cmd2 customization
735736
737+ # noinspection PyMethodMayBeStatic
736738 def _determine_metavar (self , action , default_metavar ) -> Union [str , Tuple ]:
737739 """Custom method to determine what to use as the metavar value of an action"""
738740 if action .metavar is not None :
0 commit comments