coma.hooks.run_hook¶
Run hook default factory.
- default_factory(attr_name: str = 'run') Callable[[T], T | None][source]¶
Factory for creating a run hook that executes a command.
Essentially, the attribute
attr_nameof the current value of thecommandobject is called with no arguments, and its result is stored incoma.hooks.base.InvocationData.result.Warning
If the command, at the time of registration via
command(), was a function (not a class), it is internally wrapped in a class that always has arun()method. As such, changingattr_nameto anything else than"run"will fail for function-type commands and should only be changed for class-type commands.Example
Change the run method name from
"run"to"__call__":@coma.command(run_hook=default_factory("__call__")) class Command: def __call__(self): ...