Raxol.Command.Parser (Raxol v2.0.1)
View SourceCommand parser with tab completion, history, and argument parsing.
Features:
- Command tokenization with quoted strings
- Flag and argument parsing
- Tab completion
- Command history (↑/↓ navigation)
- Fuzzy history search (Ctrl+R)
- Command aliases
Example
parser = Parser.new()
parser = Parser.register_command(parser, "echo", &echo_handler/1)
parser = Parser.register_alias(parser, "e", "echo")
{:ok, result, parser} = Parser.parse_and_execute(parser, "echo Hello World")
# => {:ok, "Hello World", parser}Tab Completion
parser = Parser.handle_key(parser, "ec")
parser = Parser.handle_key(parser, "Tab")
# Autocompletes to "echo"
Summary
Functions
Get completion candidates for current input.
Get cursor position.
Get command history.
Get current input string.
Handle a key press for interactive command input.
Create a new command parser.
Parse and execute a command string.
Register a command alias.
Register a command handler.
Types
@type t() :: %Raxol.Command.Parser{ aliases: map(), commands: map(), completion_candidates: [String.t()], completion_index: non_neg_integer(), cursor_pos: non_neg_integer(), history: [String.t()], history_index: non_neg_integer(), input: String.t(), search_mode: boolean(), search_query: String.t() }
Functions
Get completion candidates for current input.
@spec get_cursor_pos(t()) :: non_neg_integer()
Get cursor position.
Get command history.
Get current input string.
Handle a key press for interactive command input.
@spec new() :: t()
Create a new command parser.
Parse and execute a command string.
Register a command alias.
@spec register_command(t(), String.t(), command_fn()) :: t()
Register a command handler.