@@ -550,6 +550,7 @@ def _match_argument_wrapper(self, action, arg_strings_pattern) -> int:
550
550
# Patch argparse._SubParsersAction to add remove_parser function
551
551
############################################################################################################
552
552
553
+ # noinspection PyPep8Naming
553
554
def _SubParsersAction_remove_parser (self , name : str ):
554
555
"""
555
556
Removes a sub-parser from a sub-parsers group
@@ -558,23 +559,23 @@ def _SubParsersAction_remove_parser(self, name: str):
558
559
class so cmd2 can remove subcommands from a parser.
559
560
560
561
: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
562
563
"""
564
+ # Remove this subcommand from its base command's help text
563
565
for choice_action in self ._choices_actions :
564
566
if choice_action .dest == name :
565
567
self ._choices_actions .remove (choice_action )
566
568
break
567
569
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 ]
578
579
579
580
580
581
# noinspection PyProtectedMember
@@ -733,6 +734,7 @@ def _format_action_invocation(self, action) -> str:
733
734
return ', ' .join (action .option_strings ) + ' ' + args_string
734
735
# End cmd2 customization
735
736
737
+ # noinspection PyMethodMayBeStatic
736
738
def _determine_metavar (self , action , default_metavar ) -> Union [str , Tuple ]:
737
739
"""Custom method to determine what to use as the metavar value of an action"""
738
740
if action .metavar is not None :
0 commit comments