use std::process::ExitCode;
#[tokio::main]
async fn main() -> ExitCode {
match zad_cli::cli::run().await {
Ok(()) if zad_cli::cli::echo::was_echoed() => ExitCode::from(3),
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
if let zad::ZadError::RateLimited {
service,
retry_after_seconds,
retry_after_utc,
} = &e
&& json_output_requested()
{
let payload = serde_json::json!({
"error": "rate_limited",
"service": service,
"retry_after_seconds": retry_after_seconds,
"retry_after_utc": retry_after_utc,
"message": e.to_string(),
"hint": "re-run the same command with --wait to block until ready and retry automatically",
});
println!("{payload}");
} else {
zad_cli::output::error(&e.to_string());
}
ExitCode::from(1)
}
}
}
fn json_output_requested() -> bool {
std::env::args()
.skip(1)
.any(|a| a == "--json" || a.starts_with("--json="))
}