Manages command registration and execution for plugins.
Commands are stored in a plain map keyed by namespace (module) with lists of
{name, {module, function, arity}, metadata} tuples as values.
Summary
Functions
Finds and executes a command by name with timeout support.
Searches all namespaces for a command by name.
Looks up a command by namespace and name. Returns a handler function
wrapping apply(module, function, ...).
Returns the default table name atom for ETS-backed registries.
Registers a command under a namespace in the command table.
Registers commands from a plugin module's commands/0 callback.
Removes a single command from a namespace. Returns the updated table,
or the input unchanged if table is not a map.
Removes all commands for a module from the table.
Unregisters all commands for a plugin module.
Types
@type command_entry() :: {command_name(), {module(), atom(), non_neg_integer()}, command_metadata()}
@type command_metadata() :: %{ optional(:description) => String.t(), optional(:usage) => String.t(), optional(:aliases) => [String.t()], optional(:timeout) => pos_integer() }
@type command_name() :: String.t()
@type command_table() :: %{optional(module()) => [command_entry()]}
Functions
@spec execute_command(String.t(), list(), command_table()) :: term() | {:error, term()}
Finds and executes a command by name with timeout support.
@spec find_command(String.t(), command_table()) :: {:ok, {term(), command_metadata()}} | {:error, :not_found}
Searches all namespaces for a command by name.
@spec lookup_command(command_table() | term(), module(), String.t()) :: {:ok, {module(), command_handler(), non_neg_integer()}} | {:error, :not_found | :invalid_table}
Looks up a command by namespace and name. Returns a handler function
wrapping apply(module, function, ...).
@spec new() :: atom()
Returns the default table name atom for ETS-backed registries.
@spec register_command( command_table() | term(), module(), String.t(), module(), atom(), non_neg_integer() ) :: command_table() | {:error, :invalid_table}
Registers a command under a namespace in the command table.
Returns the updated table map, or {:error, :invalid_table} if
table is not a map.
@spec register_plugin_commands(module(), map(), command_table()) :: {:ok, command_table()} | {:error, term()}
Registers commands from a plugin module's commands/0 callback.
Validates handlers and metadata, checks for name conflicts against existing commands in the table.
@spec unregister_command(command_table() | term(), module(), String.t()) :: command_table() | term()
Removes a single command from a namespace. Returns the updated table,
or the input unchanged if table is not a map.
@spec unregister_commands_by_module(command_table() | term(), module()) :: command_table() | term()
Removes all commands for a module from the table.
@spec unregister_plugin_commands(module(), command_table()) :: {:ok, command_table()} | :ok
Unregisters all commands for a plugin module.