use std::net::SocketAddr; use clap::{Parser, Subcommand}; #[derive(Parser)] #[command(author, version, about, long_about = None, subcommand_required = true)] struct Command { #[command(subcommand)] command: Option, } #[derive(Subcommand)] enum Commands { Daemon { #[arg(env = "CHURN_ADDR", long)] host: SocketAddr, }, Connect { /// agent name is the hostname which other agents or servers can resolve and connect via. It should be unique #[arg(env = "CHURN_AGENT_NAME", long)] agent_name: String, #[arg(env = "CHURN_ADDR", long)] host: SocketAddr, #[arg(env = "CHURN_TOKEN", long)] token: String, }, } #[tokio::main] async fn main() -> anyhow::Result<()> { dotenv::dotenv().ok(); tracing_subscriber::fmt::init(); let cli = Command::parse(); handle_command(cli).await?; Ok(()) } async fn handle_command(cmd: Command) -> anyhow::Result<()> { match cmd.command { Some(Commands::Daemon { host }) => { tracing::info!("starting agent server on {}", host); tokio::time::sleep(std::time::Duration::from_secs(60)).await; Ok(()) } Some(Commands::Connect { host, token, agent_name, }) => todo!(), None => todo!(), } }