use clap::{Parser, Subcommand};
use koh::client::{ConnectArgs, IdArgs};
use koh::server::ServeArgs;
#[derive(Parser, Debug)]
#[command(
name = "koh",
version,
about = "koh — a resilient peer-to-peer remote shell (mosh over iroh)"
)]
struct Cli {
#[command(subcommand)]
cmd: Cmd,
}
#[derive(Subcommand, Debug)]
enum Cmd {
Serve(ServeArgs),
Connect(ConnectArgs),
Id(IdArgs),
}
#[tokio::main]
async fn main() -> std::process::ExitCode {
match dispatch(Cli::parse()).await {
Ok(Some(code)) => std::process::ExitCode::from(code as u8),
Ok(None) => std::process::ExitCode::SUCCESS,
Err(e) => {
eprintln!("koh: {e:#}");
std::process::ExitCode::FAILURE
}
}
}
async fn dispatch(cli: Cli) -> anyhow::Result<Option<u32>> {
match cli.cmd {
Cmd::Serve(args) => koh::server::serve(args).await.map(|()| None),
Cmd::Connect(args) => koh::client::connect(args).await,
Cmd::Id(args) => koh::client::run_id(args).map(|()| None),
}
}