Unregister subcommands from their base command. :param cmdset: CommandSet containing subcommands
(self, cmdset: CmdOrSet)
| 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. |