Raxol.Core.Runtime.Plugins.CommandHelper (Raxol Core v2.4.0)

Copy Markdown View Source

Handles plugin command registration and dispatch for the Plugin Manager.

Summary

Functions

Finds a command handler in the command table, normalizing the command name.

Finds the plugin ID for a given module in the plugins map.

Dispatches a command, looking it up in the table and executing the handler.

Registers commands from a plugin module's get_commands/0 callback. Returns the updated command table.

Removes all commands for a module from the command table.

Validates that command arguments are a list of strings or numbers.

Functions

find_plugin_for_command(command_table, command_name, namespace, arity)

@spec find_plugin_for_command(
  map(),
  atom() | String.t(),
  module() | nil,
  non_neg_integer()
) :: {:ok, {module(), atom(), non_neg_integer()}} | :not_found

Finds a command handler in the command table, normalizing the command name.

find_plugin_id_by_module(plugins, module)

@spec find_plugin_id_by_module(map(), module()) :: String.t() | nil

Finds the plugin ID for a given module in the plugins map.

handle_command(command_table, command_name_str, namespace, args, state)

@spec handle_command(map(), String.t(), module() | nil, list() | nil, map()) ::
  {:ok, map()} | {:error, atom()} | {:error, atom(), map()}

Dispatches a command, looking it up in the table and executing the handler.

register_plugin_commands(plugin_module, plugin_state, command_table)

@spec register_plugin_commands(module(), map(), map()) :: map()

Registers commands from a plugin module's get_commands/0 callback. Returns the updated command table.

unregister_plugin_commands(command_table, plugin_module)

@spec unregister_plugin_commands(map(), module()) :: map()

Removes all commands for a module from the command table.

validate_command_args(args)

@spec validate_command_args(term()) :: :ok | {:error, :invalid_args}

Validates that command arguments are a list of strings or numbers.