Yeesh.Registry (Yeesh v0.8.2)

View Source

ETS-backed command registry.

Stores command modules keyed by their name. Only the help built-in is registered on application start. Additional built-ins are registered when the terminal component mounts according to the :builtins option (defaults to :help). Consumer commands are also registered on mount.

See resolve_builtins/1 for the accepted values of :builtins.

Summary

Functions

Returns the list of built-in command modules.

Returns a specification to start this module under a supervisor.

Returns command names matching the given prefix.

Returns all registered command names.

Returns all registered {name, module} pairs.

Looks up a command module by name.

Finds the longest registered command that matches a prefix of the given tokens. Returns {:ok, command_name, remaining_args} if any registered command matches, otherwise :error.

Normalizes a command name: trims outer whitespace and collapses any run of internal whitespace into a single space.

Registers a command module.

Registers multiple command modules.

Clears the registry and re-registers only the default builtins (:help).

Resolves a builtins option into a list of command modules.

Starts the registry.

Types

builtins_opt()

@type builtins_opt() :: :all | :none | :help | [module()]

Functions

builtin_commands()

@spec builtin_commands() :: [module()]

Returns the list of built-in command modules.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

completions_for(prefix)

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

Returns command names matching the given prefix.

list()

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

Returns all registered command names.

list_all()

@spec list_all() :: [{String.t(), module()}]

Returns all registered {name, module} pairs.

lookup(name)

@spec lookup(String.t()) :: {:ok, module()} | :error

Looks up a command module by name.

match_command(tokens)

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

Finds the longest registered command that matches a prefix of the given tokens. Returns {:ok, command_name, remaining_args} if any registered command matches, otherwise :error.

Used by the executor to resolve multi-word commands after tokenization.

normalize_name(name)

@spec normalize_name(String.t()) :: String.t()

Normalizes a command name: trims outer whitespace and collapses any run of internal whitespace into a single space.

register(command_module)

@spec register(module()) :: :ok

Registers a command module.

register_all(modules)

@spec register_all([module()]) :: :ok

Registers multiple command modules.

reset()

@spec reset() :: :ok

Clears the registry and re-registers only the default builtins (:help).

resolve_builtins(modules)

@spec resolve_builtins(builtins_opt()) :: [module()]

Resolves a builtins option into a list of command modules.

Accepted values:

  • :all -- all built-in commands
  • :none -- no built-in commands
  • :help -- only the help command (default)
  • a list of command modules -- those exact modules

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the registry.