mini_arcade.cli.registry¶
Registry for command classes with alias support.
Classes¶
Registry for command classes (stores classes, not instances). |
Module Contents¶
- class mini_arcade.cli.registry.CommandRegistry[source]¶
Bases:
mini_arcade.utils.implementation_registry.ImplementationRegistry[mini_arcade.cli.command_protocol.CommandProtocol]Registry for command classes (stores classes, not instances). Adds alias resolution on top of ImplementationRegistry.
- Variables:
implementation_base – ClassVar[type]: The base class for registered commands.
_alias_map – ClassVar[MutableMapping[str, str]]: Mapping of aliases to primary command names.
- classmethod register(name: str, impl_class: Type[mini_arcade.cli.command_protocol.CommandProtocol], *, replace: bool = False, aliases: tuple[str, Ellipsis] = (), abstract: bool = False)[source]¶
Register a command class under a primary name and optional aliases. Abstract commands are skipped.
- Parameters:
name (str) – The primary name of the command.
impl_class (Type[CommandProtocol]) – The command class to register.
replace (bool) – Whether to replace an existing registration.
aliases (tuple[str, ...]) – Optional tuple of alias names for the command.
abstract (bool) – Whether the command is abstract (not registered).
- classmethod implementation(name: str | None = None, *, replace: bool = False) Callable[[Type[mini_arcade.cli.command_protocol.CommandProtocol]], Type[mini_arcade.cli.command_protocol.CommandProtocol]][source]¶
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
- Parameters:
name (Optional[str]) – Optional command name; defaults to class name lowercased.
replace (bool) – Whether to replace an existing command with the same name.
- classmethod get(name: str) Type[mini_arcade.cli.command_protocol.CommandProtocol][source]¶
Get a command class by primary name or alias.
- Parameters:
name (str) – The primary name or alias of the command.
- Returns:
The command class.
- Return type:
Type[CommandProtocol]
- classmethod try_get(name: str) Type[mini_arcade.cli.command_protocol.CommandProtocol] | None[source]¶
Try to get a command class by primary name or alias.
- Parameters:
name (str) – The primary name or alias of the command.
- Returns:
The command class, or None if not found.
- Return type:
Optional[Type[CommandProtocol]]
- classmethod contains(name: str) bool[source]¶
Check if a command is registered by primary name or alias.
- Parameters:
name (str) – The primary name or alias of the command.
- Returns:
Whether the command is registered.
- Return type:
bool
- classmethod names() list[str][source]¶
Primary command names only (aliases excluded).
- Returns:
List of primary command names.
- Return type:
list[str]
- classmethod all_with_aliases() Mapping[str, Type[mini_arcade.cli.command_protocol.CommandProtocol]][source]¶
Convenience: primary names plus alias keys.
- Returns:
Mapping of all names (primary + aliases) to command classes.
- Return type:
Mapping[str, Type[CommandProtocol]]