INNER CODE UNIT · Python
get_command
mikel-brostrom/boxmot · boxmot/engine/cli.py:84
def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None:
"""Import and cache only the command selected by Click."""
if command := self.commands.get(cmd_name):
return command
spec = _COMMAND_SPEC_BY_NAME.get(cmd_name)
if spec is None:
return None
module = importlib.import_module(spec.module)
command = getattr(module, spec.attribute)
if not isinstance(command, click.Command):
raise TypeError(f"{spec.module}.{spec.attribute} is not a Click command")
if command.name != spec.name:
raise ValueError(
f"CLI manifest registers {spec.module}.{spec.attribute} as {spec.name!r}, "
f"but the command declares {command.name!r}"
)