mod agent;
mod config;
mod http;
mod session;
mod ws;
use anyhow::{bail, Result};
use crate::config::{config_path, init_config, load_config, TransportConfig};
use crate::http::run_cloudflared;
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let sub = args.get(1).map(String::as_str);
if sub == Some("init") {
init_config()?;
return Ok(());
}
let cfg = if config_path()?.exists() {
load_config()?
} else {
eprintln!("No config at {}", config_path()?.display());
eprintln!("Let's set one up:");
init_config()?
};
let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build()?;
rt.block_on(async move {
match cfg.transports.as_slice() {
[] => bail!("No transports configured. Re-run `mezame init`."),
[one] => match one.clone() {
TransportConfig::Cloudflared { bind } => run_cloudflared(cfg, bind).await
},
_ => bail!(
"Running more than one transport at once is not yet supported. \
Leave a single entry in `transports` until multi-transport ships."
)
}
})
}