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

View Source

Handles registration and execution of commands provided by plugins.

This module maintains a registry of commands provided by plugins and integrates them with the main command execution system. It ensures that plugin commands are properly isolated and cannot interfere with core system functionality.

Summary

Functions

Returns a specification to start this module under a supervisor.

Execute a plugin command with the given arguments.

Get help text for a specific command.

List all registered plugin commands.

Register a new command provided by a plugin.

Start the plugin commands registry.

Unregister a previously registered command.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

execute(command_name, args, context \\ %{})

@spec execute(String.t(), list(), map()) :: {:ok, term()} | {:error, term()}

Execute a plugin command with the given arguments.

Parameters

  • command_name - The name of the command to execute
  • args - Arguments to pass to the command
  • context - Execution context for the command

Returns

  • {:ok, result} if execution was successful
  • {:error, reason} if execution failed

get_help(command_name)

@spec get_help(String.t()) :: {:ok, String.t()} | {:error, term()}

Get help text for a specific command.

Parameters

  • command_name - The name of the command

Returns

  • {:ok, help_text} if command exists
  • {:error, :not_found} if command does not exist

handle_shutdown(reason, state)

list_commands()

@spec list_commands() :: map()

List all registered plugin commands.

Returns

Map with command names as keys and metadata as values

register(command_name, handler, help_text, options \\ [])

@spec register(String.t(), module(), String.t(), keyword()) :: :ok | {:error, term()}

Register a new command provided by a plugin.

Parameters

  • command_name - The name of the command (should be prefixed with plugin namespace)
  • handler - Module that will handle the command
  • help_text - Help text to display for the command
  • options - Additional options for command registration

Returns

  • :ok if command was registered
  • {:error, :already_registered} if command name is already in use
  • {:error, reason} for other errors

start_link(opts \\ [])

Start the plugin commands registry.

unregister(command_name)

@spec unregister(String.t()) :: :ok | {:error, term()}

Unregister a previously registered command.

Parameters

  • command_name - The name of the command to unregister

Returns

  • :ok if command was unregistered
  • {:error, :not_found} if command was not registered