nanover.core.commands module

class nanover.core.commands.CommandRegistration(*, name: str, arguments: dict, handler: Callable[..., dict | None] | Callable[[], dict | None])

Bases: object

arguments: dict
handler: Callable[[...], dict | None] | Callable[[], dict | None]
name: str
run(arguments: dict)
class nanover.core.commands.CommandService(add_list_command=True)

Bases: object

Implementation of the Command service, enabling services to register arbitrary commands which are run as callbacks.

property commands: dict[str, CommandRegistration]

Gets a copy of the commands that have been registered, as CommandRegistration, including their names, default arguments and registered callback.

Returns:

A copy of the dictionary of commands that have been registered.

register_command(name: str, callback: Callable[[...], dict | None] | Callable[[], dict | None], default_arguments: dict | None = None)

Registers a command with this service

Parameters:
  • name – Name of the command to register

  • callback – Method to be called whenever the given command name is run by a client.

  • default_arguments – A dictionary of the arguments of the callback and their default values.

Raises:

ValueError – Raised when a command with the same name already exists.

run_command(name: str, arguments: dict)
unregister_command(name)

Deletes a command from this service.

Parameters:

name – Name of the command to delete