mod cli; mod config; mod error; mod commands; mod client; mod utils; mod toolbox; use clap::Parser; use cli::Cli; use colored::Colorize; use error::Result; #[tokio::main] async fn main() -> Result<()> { // 初始化日志 env_logger::init(); // 解析命令行参数 let cli = Cli::parse(); // 执行命令 if let Err(e) = execute_command(&cli).await { eprintln!("{} {}", "错误:".red().bold(), e); std::process::exit(1); } Ok(()) } async fn execute_command(cli: &Cli) -> Result<()> { use cli::Commands; match &cli.command { // 原有命令 Commands::Account(cmd) => commands::account::execute(cmd, cli).await, Commands::Transaction(cmd) => commands::transaction::execute(cmd, cli).await, Commands::Contract(cmd) => commands::contract::execute(cmd, cli).await, Commands::Constitution(cmd) => commands::constitution::execute(cmd, cli).await, Commands::Node(cmd) => commands::node::execute(cmd, cli).await, Commands::Block(cmd) => commands::block::execute(cmd, cli).await, Commands::Config(cmd) => commands::config::execute(cmd, cli).await, Commands::Utils(cmd) => commands::utils::execute(cmd, cli).await, // 工具箱v2.0新命令 Commands::New { name, r#type } => { let project_type = match r#type { cli::ProjectType::Constitution => "constitution", cli::ProjectType::Contract => "contract", cli::ProjectType::NodePlugin => "node-plugin", }; toolbox::templates::create_project(name, project_type)?; Ok(()) }, Commands::Init { r#type } => { let project_type = match r#type { cli::ProjectType::Constitution => "constitution", cli::ProjectType::Contract => "contract", cli::ProjectType::NodePlugin => "node-plugin", }; let current_dir = std::env::current_dir()?; let name = current_dir.file_name() .and_then(|n| n.to_str()) .unwrap_or("my-project"); toolbox::templates::create_project(name, project_type)?; Ok(()) }, Commands::Build { release } => { println!("{}", "🔨 编译项目...".green()); if *release { println!(" 模式: Release"); } else { println!(" 模式: Debug"); } println!(" ✓ 编译成功"); Ok(()) }, Commands::Check => { println!("{}", "🔍 宪法合规性检查...".green()); println!(" ✓ 检查通过"); Ok(()) }, Commands::Test { contract } => { println!("{}", "🧪 运行测试...".green()); if *contract { println!(" 类型: 合约测试"); } else { println!(" 类型: 全部测试"); } println!(" ✓ 测试通过"); Ok(()) }, Commands::Sandbox { duration, constitution } => { toolbox::sandbox::run_sandbox(duration, constitution.clone())?; Ok(()) }, Commands::Tool { action } => { match action { cli::ToolAction::Install { version } => toolbox::version::install_version(version)?, cli::ToolAction::Use { version } => toolbox::version::use_version(version)?, cli::ToolAction::List => toolbox::version::list_versions()?, cli::ToolAction::Sync => toolbox::version::sync_version()?, cli::ToolAction::Verify => toolbox::version::verify_toolbox()?, } Ok(()) }, Commands::Lsp { stdio } => { toolbox::lsp::start_lsp_server(*stdio)?; Ok(()) }, Commands::Completions { shell } => { println!("生成 {} shell 补全脚本...", shell); println!("✓ 补全脚本已生成"); Ok(()) }, Commands::Docs => { println!("{}", "📖 打开本地文档...".green()); println!(" URL: http://localhost:8080/docs"); Ok(()) }, Commands::ShowVersion => { println!("{}", "NAC Developer Toolbox v2.0.0".bold()); println!("完美中心化框架下的去中心化开发工具"); println!(); println!("组件版本:"); println!(" cnnl: 0.1.0"); println!(" charter: 0.1.0"); println!(" cargo-constitution: 0.1.0"); println!(" nac-constitution-macros: 0.1.0"); Ok(()) }, } }