Module builder

Module builder 

Source
Expand description

Fluent builder API for creating CLI/REPL applications

This module provides a builder pattern for easily constructing CLI and REPL applications with minimal boilerplate.

§Example

use dynamic_cli::prelude::*;
use std::collections::HashMap;

// Define context
#[derive(Default)]
struct MyContext;

impl ExecutionContext for MyContext {
    fn as_any(&self) -> &dyn std::any::Any { self }
    fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self }
}

// Define handler
struct HelloCommand;

impl CommandHandler for HelloCommand {
    fn execute(
        &self,
        _context: &mut dyn ExecutionContext,
        args: &HashMap<String, String>,
    ) -> dynamic_cli::Result<()> {
        println!("Hello!");
        Ok(())
    }
}

// Build and run
CliBuilder::new()
    .config_file("commands.yaml")
    .context(Box::new(MyContext::default()))
    .register_handler("hello_handler", Box::new(HelloCommand))
    .build()?
    .run()

Structs§

CliApp
Built CLI/REPL application
CliBuilder
Fluent builder for creating CLI/REPL applications