MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _unregister_subcommands

Method _unregister_subcommands

cmd2/cmd2.py:1141–1166  ·  view source on GitHub ↗

Unregister subcommands from their base command. :param cmdset: CommandSet containing subcommands

(self, cmdset: CmdOrSet)

Source from the content-addressed store, hash-verified

1139 raise CommandSetRegistrationError(str(ex)) from ex
1140
1141 def _unregister_subcommands(self, cmdset: CmdOrSet) -> None:
1142 """Unregister subcommands from their base command.
1143
1144 :param cmdset: CommandSet containing subcommands
1145 """
1146 if not (cmdset is self or cmdset in self._installed_command_sets):
1147 raise CommandSetRegistrationError("Cannot unregister subcommands with an unregistered CommandSet")
1148
1149 # find methods that have the required attributes necessary to be recognized as a sub-command
1150 methods = inspect.getmembers(
1151 cmdset,
1152 predicate=lambda meth: (
1153 isinstance(meth, Callable) # type: ignore[arg-type]
1154 and hasattr(meth, constants.SUBCMD_ATTR_NAME)
1155 and hasattr(meth, constants.SUBCMD_ATTR_COMMAND)
1156 and hasattr(meth, constants.CMD_ATTR_ARGPARSER)
1157 ),
1158 )
1159
1160 # iterate through all matching methods
1161 for _method_name, method in methods:
1162 subcommand_name = getattr(method, constants.SUBCMD_ATTR_NAME)
1163 full_command_name = getattr(method, constants.SUBCMD_ATTR_COMMAND)
1164
1165 with contextlib.suppress(ValueError):
1166 self.detach_subcommand(full_command_name, subcommand_name)
1167
1168 def get_root_parser_and_subcmd_path(self, command: str) -> tuple[Cmd2ArgumentParser, list[str]]:
1169 """Tokenize a command string and resolve the associated root parser and relative subcommand path.

Callers 2

test_subcommandsFunction · 0.80

Calls 2

detach_subcommandMethod · 0.95

Tested by 1

test_subcommandsFunction · 0.64