mini_arcade.cli.registry ======================== .. py:module:: mini_arcade.cli.registry .. autoapi-nested-parse:: Registry for command classes with alias support. Classes ------- .. autoapisummary:: mini_arcade.cli.registry.CommandRegistry Module Contents --------------- .. py:class:: CommandRegistry Bases: :py:obj:`mini_arcade.utils.implementation_registry.ImplementationRegistry`\ [\ :py:obj:`mini_arcade.cli.command_protocol.CommandProtocol`\ ] Registry for command classes (stores classes, not instances). Adds alias resolution on top of ImplementationRegistry. :ivar implementation_base: ClassVar[type]: The base class for registered commands. :ivar _alias_map: ClassVar[MutableMapping[str, str]]: Mapping of aliases to primary command names. .. py:attribute:: implementation_base :type: ClassVar[type] .. py:method:: __init_subclass__(**kwargs) :classmethod: .. py:method:: register(name: str, impl_class: Type[mini_arcade.cli.command_protocol.CommandProtocol], *, replace: bool = False, aliases: tuple[str, Ellipsis] = (), abstract: bool = False) :classmethod: Register a command class under a primary `name` and optional `aliases`. Abstract commands are skipped. :param name: The primary name of the command. :type name: str :param impl_class: The command class to register. :type impl_class: Type[CommandProtocol] :param replace: Whether to replace an existing registration. :type replace: bool :param aliases: Optional tuple of alias names for the command. :type aliases: tuple[str, ...] :param abstract: Whether the command is abstract (not registered). :type abstract: bool .. py:method:: implementation(name: Optional[str] = None, *, replace: bool = False) -> Callable[[Type[mini_arcade.cli.command_protocol.CommandProtocol]], Type[mini_arcade.cli.command_protocol.CommandProtocol]] :classmethod: Decorator for registering commands. Pulls metadata from class attributes: - name (str) if not provided here, inferred from class name - aliases (tuple[str, ...]) optional - abstract (bool) if True, not registered :param name: Optional command name; defaults to class name lowercased. :type name: Optional[str] :param replace: Whether to replace an existing command with the same name. :type replace: bool .. py:method:: get(name: str) -> Type[mini_arcade.cli.command_protocol.CommandProtocol] :classmethod: Get a command class by primary name or alias. :param name: The primary name or alias of the command. :type name: str :return: The command class. :rtype: Type[CommandProtocol] .. py:method:: try_get(name: str) -> Optional[Type[mini_arcade.cli.command_protocol.CommandProtocol]] :classmethod: Try to get a command class by primary name or alias. :param name: The primary name or alias of the command. :type name: str :return: The command class, or None if not found. :rtype: Optional[Type[CommandProtocol]] .. py:method:: contains(name: str) -> bool :classmethod: Check if a command is registered by primary name or alias. :param name: The primary name or alias of the command. :type name: str :return: Whether the command is registered. :rtype: bool .. py:method:: names() -> list[str] :classmethod: Primary command names only (aliases excluded). :return: List of primary command names. :rtype: list[str] .. py:method:: all_with_aliases() -> Mapping[str, Type[mini_arcade.cli.command_protocol.CommandProtocol]] :classmethod: Convenience: primary names plus alias keys. :return: Mapping of all names (primary + aliases) to command classes. :rtype: Mapping[str, Type[CommandProtocol]] .. py:method:: unregister(name: str) :classmethod: Unregister a command by primary name or alias (removes its aliases too). :param name: The primary name or alias of the command to unregister. :type name: str .. py:method:: clear() :classmethod: Clear all registered commands and aliases.