2026-03-11 23:43:24 +08:00
|
|
|
use clap::Parser;
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
2026-03-19 23:49:16 +08:00
|
|
|
mod commands; // 引入 commands 模块
|
|
|
|
|
mod internal; // 引入 internal 模块
|
|
|
|
|
mod utils; // 引入 utils 通用工具模块
|
2026-03-11 23:43:24 +08:00
|
|
|
|
|
|
|
|
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,
|
2026-03-07 10:45:56 +08:00
|
|
|
}
|
2026-03-11 23:43:24 +08:00
|
|
|
|
2026-03-19 23:49:16 +08:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> Result<()> {
|
2026-03-11 23:43:24 +08:00
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
|
|
|
|
if cli.debug {
|
|
|
|
|
println!("[DEBUG] 调试模式已开启");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据子命令分发逻辑
|
|
|
|
|
match cli.command {
|
|
|
|
|
CliCommands::Server(args) => commands::server::execute(args)?,
|
2026-03-19 23:49:16 +08:00
|
|
|
CliCommands::Db(args) => commands::db::execute(args).await?,
|
|
|
|
|
CliCommands::Config(args) => commands::config::execute(args)?,
|
|
|
|
|
CliCommands::Report(args) => commands::report::execute(args)?,
|
2026-03-11 23:43:24 +08:00
|
|
|
// 未来扩展新命令时,只需在这里添加新的匹配臂
|
|
|
|
|
// CliCommands::NewFeature(args) => commands::new_feature::execute(args)?,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|