Module repl_parser

Module repl_parser 

Source
Expand description

REPL line parser

This module provides the ReplParser which parses interactive REPL command lines. It works with the CommandRegistry to resolve command names and aliases, then delegates to CliParser for argument parsing.

§Example

use dynamic_cli::parser::repl_parser::ReplParser;
use dynamic_cli::registry::CommandRegistry;
use dynamic_cli::config::schema::{CommandDefinition, ArgumentType};
use dynamic_cli::executor::CommandHandler;
use dynamic_cli::context::ExecutionContext;
use std::collections::HashMap;

// Create registry
let mut registry = CommandRegistry::new();

// Register a command
let definition = CommandDefinition {
    name: "hello".to_string(),
    aliases: vec!["hi".to_string()],
    description: "Say hello".to_string(),
    required: false,
    arguments: vec![],
    options: vec![],
    implementation: "handler".to_string(),
};

// Dummy handler for example
struct DummyHandler;
impl CommandHandler for DummyHandler {
    fn execute(
        &self,
        _context: &mut dyn ExecutionContext,
        _args: &HashMap<String, String>,
    ) -> dynamic_cli::error::Result<()> {
        Ok(())
    }
}

registry.register(definition, Box::new(DummyHandler)).unwrap();

// Parse a REPL line
let parser = ReplParser::new(&registry);
let parsed = parser.parse_line("hi").unwrap();
assert_eq!(parsed.command_name, "hello");

Structs§

ParsedCommand
Parsed REPL command
ReplParser
REPL line parser