Uninstalls a CommandSet and unloads all associated commands. :param cmdset: CommandSet to uninstall
(self, cmdset: CommandSet[Any])
| 1002 | setattr(self, help_func_name, cmd_help) |
| 1003 | |
| 1004 | def unregister_command_set(self, cmdset: CommandSet[Any]) -> None: |
| 1005 | """Uninstalls a CommandSet and unloads all associated commands. |
| 1006 | |
| 1007 | :param cmdset: CommandSet to uninstall |
| 1008 | """ |
| 1009 | if cmdset in self._installed_command_sets: |
| 1010 | self._check_uninstallable(cmdset) |
| 1011 | cmdset.on_unregister() |
| 1012 | self._unregister_subcommands(cmdset) |
| 1013 | |
| 1014 | methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers( |
| 1015 | cmdset, |
| 1016 | predicate=lambda meth: ( # type: ignore[arg-type] |
| 1017 | isinstance(meth, Callable) # type: ignore[arg-type] |
| 1018 | and hasattr(meth, "__name__") |
| 1019 | and meth.__name__.startswith(COMMAND_FUNC_PREFIX) |
| 1020 | ), |
| 1021 | ) |
| 1022 | |
| 1023 | for cmd_func_name, command_method in methods: |
| 1024 | command = cmd_func_name[len(COMMAND_FUNC_PREFIX) :] |
| 1025 | |
| 1026 | # Enable the command before uninstalling it to make sure we remove both |
| 1027 | # the real functions and the ones used by the DisabledCommand object. |
| 1028 | if command in self.disabled_commands: |
| 1029 | self.enable_command(command) |
| 1030 | |
| 1031 | if command in self._cmd_to_command_sets: |
| 1032 | del self._cmd_to_command_sets[command] |
| 1033 | |
| 1034 | # Only remove the parser if this is the actual |
| 1035 | # command since command synonyms don't own it. |
| 1036 | if cmd_func_name == command_method.__name__: |
| 1037 | self.command_parsers.remove(command_method) |
| 1038 | |
| 1039 | if hasattr(self, COMPLETER_FUNC_PREFIX + command): |
| 1040 | delattr(self, COMPLETER_FUNC_PREFIX + command) |
| 1041 | if hasattr(self, HELP_FUNC_PREFIX + command): |
| 1042 | delattr(self, HELP_FUNC_PREFIX + command) |
| 1043 | |
| 1044 | delattr(self, cmd_func_name) |
| 1045 | |
| 1046 | cmdset.on_unregistered() |
| 1047 | self._installed_command_sets.remove(cmdset) |
| 1048 | |
| 1049 | def _check_uninstallable(self, cmdset: CommandSet[Any]) -> None: |
| 1050 | cmdset_id = id(cmdset) |