PicoBot/src/main.rs
oudecheng cda14360af chore: 建立工程化基线(rustfmt + clippy + CI + eslint + prettier)
配置:
- rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化
- Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则
- .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI
- Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features
- web: eslint flat config + prettier 配置 + package.json 脚本与依赖
- src/main.rs: loop→while 修复 clippy::never_loop

对抗性审查发现并修复:
- eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error
- 前端 lint 未接入 CI,现已补上 Lint 步骤
- Makefile 与 CI 的 clippy flags 不一致,已对齐
2026-08-03 23:24:02 +08:00

73 lines
2.0 KiB
Rust

use clap::{CommandFactory, Parser};
#[derive(Parser)]
#[command(name = "picobot")]
#[command(about = "A CLI chatbot", long_about = None)]
enum Command {
/// Interactive configuration wizard
Init {
/// Force overwrite existing config
#[arg(short, long)]
force: bool,
/// Only configure provider, skip channels
#[arg(long)]
skip_channels: bool,
},
/// Connect to gateway
Agent {
/// Gateway WebSocket URL (e.g., ws://127.0.0.1:19876/ws)
#[arg(long)]
gateway_url: Option<String>,
},
/// Start gateway server
Gateway {
/// Host to bind to
#[arg(long)]
host: Option<String>,
/// Port to listen on
#[arg(long)]
port: Option<u16>,
},
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
picobot::bootstrap::initialize_process_runtime();
let mut cmd = Command::command();
// If no arguments, print help
if std::env::args().len() <= 1 {
cmd.print_help()?;
println!();
return Ok(());
}
match Command::parse() {
Command::Init {
force,
skip_channels,
} => {
let mut wizard = picobot::cli::InitWizard::new();
wizard.run(force, skip_channels).await?;
}
Command::Agent { gateway_url } => {
let config = picobot::config::Config::load_default().ok();
let url = gateway_url
.or_else(|| config.as_ref().map(|c| c.client.gateway_url.clone()))
.unwrap_or_else(|| "ws://127.0.0.1:19876/ws".to_string());
picobot::client::run(&url).await?;
}
Command::Gateway { host, port } => {
let mut should_restart = true;
while should_restart {
should_restart = picobot::gateway::run(host.clone(), port).await?;
if should_restart {
tracing::info!("Gateway restarting...");
}
}
}
}
Ok(())
}