use std::path::PathBuf;
use std::process::ExitCode;
pub fn run(mut args: impl Iterator<Item = String>) -> ExitCode {
let result = (|| {
anyhow::ensure!(
args.next().as_deref() == Some("run") && args.next().as_deref() == Some("--config"),
"usage: haematite assistant run --config <seat.json>"
);
let path = PathBuf::from(
args.next()
.ok_or_else(|| anyhow::anyhow!("seat_config_required"))?,
);
anyhow::ensure!(args.next().is_none(), "assistant_unexpected_argument");
let seat = super::config::Seat::load(&path)?;
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(super::host::serve(&seat))
})();
match result {
Ok(status) => ExitCode::from(u8::try_from(status).unwrap_or(1)),
Err(error) => {
eprintln!("haematite assistant: {error}");
ExitCode::FAILURE
}
}
}