PicoBot/src/main.rs

49 lines
1.3 KiB
Rust

use clap::{Parser, CommandFactory};
#[derive(Parser)]
#[command(name = "picobot")]
#[command(about = "A CLI chatbot", long_about = None)]
enum Command {
/// 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>> {
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::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 } => {
picobot::gateway::run(host, port).await?;
}
}
Ok(())
}