use clap::Parser; use anyhow::Result; mod commands; // 引入 commands 模块 mod internal; // 引入 internal 模块 mod utils; // 引入 utils 通用工具模块 use commands::CliCommands; #[derive(Parser)] #[command(name = "sunhpc")] #[command(author = "Qichao.Sun")] #[command(version = "0.1.0")] #[command(about = "一个可扩展的多级命令行工具框架", long_about = None)] struct Cli { /// 全局调试模式 #[arg(short, long, global = true)] debug: bool, /// 子命令入口 #[command(subcommand)] command: CliCommands, } #[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); if cli.debug { println!("[DEBUG] 调试模式已开启"); } // 根据子命令分发逻辑 match cli.command { CliCommands::Server(args) => commands::server::execute(args)?, CliCommands::Db(args) => commands::db::execute(args).await?, CliCommands::Config(args) => commands::config::execute(args)?, CliCommands::Report(args) => commands::report::execute(args)?, // 未来扩展新命令时,只需在这里添加新的匹配臂 // CliCommands::NewFeature(args) => commands::new_feature::execute(args)?, } Ok(()) }