use std::net::SocketAddr;
use std::time::Duration;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "opencord",
about = "Ephemeral chat servers with automatic shutdown"
)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Server {
#[arg(long, default_value = "2h", value_parser = parse_lifetime)]
lifetime: Duration,
#[arg(long, default_value = "127.0.0.1:8080")]
addr: SocketAddr,
},
Client {
name: String,
invite_link: String,
},
}
fn parse_lifetime(s: &str) -> Result<Duration, String> {
opencord::duration::parse_duration(s)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
match cli.command {
Command::Server { lifetime, addr } => {
opencord::server::run(addr, lifetime).await?;
}
Command::Client { name, invite_link } => {
let result = opencord::client::run(&invite_link, &name).await;
let code = if result.is_ok() { 0 } else { 1 };
std::process::exit(code);
}
}
Ok(())
}