命令框架模块构建完成
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -1,3 +1,42 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
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,
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
Reference in New Issue
Block a user