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_name of the current value of the command object is called with no arguments, and its result is stored in coma.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 a run() method. As such, changing attr_name to 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):
        ...
Parameters:

attr_name (str) – The name of the command attribute to call.

Returns:

A hook with run_hook semantics.

Return type:

Hook