Files
sunhpc-rs/src/main.rs

42 lines
1.0 KiB
Rust
Raw Normal View History

2026-03-11 23:43:24 +08:00
use clap::Parser;
use anyhow::Result;
// 引入 commands 模块
mod commands;
mod utils; // 假设有通用工具
use commands::CliCommands;
/// 我的超级 CLI 工具
#[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,
2026-03-07 10:45:56 +08:00
}
2026-03-11 23:43:24 +08:00
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)?,
// 未来扩展新命令时,只需在这里添加新的匹配臂
// CliCommands::NewFeature(args) => commands::new_feature::execute(args)?,
}
Ok(())
}