mod-cli 0.6.4

A fully customizable, feature-rich CLI framework for Rust. Define commands, prefixes, styled output, and more—built for flexibility and speed.
Documentation
use modcli::command::Command;
use modcli::loader::CommandRegistry;

struct HelloCommand;

impl Command for HelloCommand {
    fn name(&self) -> &str {
        "hello"
    }

    fn help(&self) -> Option<&str> {
        Some("Prints a greeting. Usage: hello [name]")
    }

    fn execute(&self, args: &[String]) {
        let target = args.first().map(String::as_str).unwrap_or("world");
        println!("👋 Hello, {target}!");
    }
}

fn main() {
    let args: Vec<String> = std::env::args().skip(1).collect();

    let mut registry = CommandRegistry::new();
    registry.register(Box::new(HelloCommand));

    match args.split_first() {
        Some((cmd, rest)) => {
            if cmd == "help" {
                println!("Available commands:");
                for command in registry.all() {
                    if !command.hidden() {
                        println!(
                            "  {:<10} {}",
                            command.name(),
                            command.help().unwrap_or("No description")
                        );
                    }
                }
            } else {
                registry.execute(cmd, rest);
            }
        }
        None => {
            println!("No command given. Try: `demo hello` or `demo help`");
        }
    }
}