Raxol.Core.Runtime.Plugins.CommandRegistry (Raxol v0.2.0)

View Source

Manages commands registered by plugins using an ETS table.

Provides functions to register, unregister, and look up commands.

Summary

Functions

Looks up the handler {module, function, arity} for a command name and namespace.

Creates a new ETS table for the command registry.

Unregisters all commands associated with a specific module.

Types

command_entry()

@type command_entry() :: {module(), atom(), integer() | nil}

command_key()

@type command_key() :: {namespace(), command_name()}

command_name()

@type command_name() :: String.t()

namespace()

@type namespace() :: atom() | nil

table_name()

@type table_name() :: atom()

Functions

lookup_command(table, namespace, command_name)

@spec lookup_command(table_name(), namespace(), command_name()) ::
  {:ok, command_entry()} | {:error, :not_found}

Looks up the handler {module, function, arity} for a command name and namespace.

new()

@spec new() :: table_name()

Creates a new ETS table for the command registry.

Returns the name of the created table.

register_command(table, namespace, command_name, module, function, arity)

@spec register_command(
  table_name(),
  namespace(),
  command_name(),
  module(),
  atom(),
  integer() | nil
) :: :ok | {:error, :already_registered}

Registers a command provided by a plugin.

Args:

  • table: The ETS table name.
  • command_name: The name the command will be invoked by.
  • module: The plugin module implementing the command.
  • function: The function within the module to call.
  • arity: The arity of the function.

Returns :ok or {:error, :already_registered}.

unregister_command(table, namespace, command_name)

@spec unregister_command(table_name(), namespace(), command_name()) :: :ok

Unregisters a command.

unregister_commands_by_module(table, module_to_remove)

@spec unregister_commands_by_module(table_name(), module()) :: :ok

Unregisters all commands associated with a specific module.

Useful when a plugin is unloaded.