Raxol.Terminal.Commands.Registry (Raxol v0.5.0)

View Source

Manages terminal commands with advanced features:

  • Command registration and lookup
  • Command validation and execution
  • Command history tracking
  • Command completion suggestions

Summary

Functions

Clears the command history.

Executes a command with the given arguments.

Gets command completion suggestions for the given input.

Gets the command history.

Gets the current registry metrics.

Creates a new command registry with the given options.

Registers a new command in the registry.

Types

command()

@type command() :: %{
  name: command_name(),
  description: command_description(),
  handler: command_handler(),
  aliases: command_aliases(),
  usage: command_usage(),
  completion: command_completion()
}

command_aliases()

@type command_aliases() :: [String.t()]

command_completion()

@type command_completion() :: function() | nil

command_description()

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

command_handler()

@type command_handler() :: function()

command_metrics()

@type command_metrics() :: %{
  registrations: integer(),
  executions: integer(),
  completions: integer(),
  validations: integer()
}

command_name()

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

command_usage()

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

t()

@type t() :: %Raxol.Terminal.Commands.Registry{
  commands: %{required(String.t()) => command()},
  history: [String.t()],
  max_history: integer(),
  metrics: command_metrics()
}

Functions

clear_history(registry)

@spec clear_history(t()) :: t()

Clears the command history.

execute_command(registry, command_name, args)

@spec execute_command(t(), String.t(), [String.t()]) ::
  {:ok, t(), term()} | {:error, term()}

Executes a command with the given arguments.

get_completions(registry, input)

@spec get_completions(t(), String.t()) :: {:ok, t(), [String.t()]} | {:error, term()}

Gets command completion suggestions for the given input.

get_history(registry)

@spec get_history(t()) :: [String.t()]

Gets the command history.

get_metrics(registry)

@spec get_metrics(t()) :: map()

Gets the current registry metrics.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a new command registry with the given options.

register_command(registry, command)

@spec register_command(t(), command()) :: {:ok, t()} | {:error, term()}

Registers a new command in the registry.