hafas-sim 1.0.0

Fake HAFAS ReST server built from trimmed RMV responses, for tests
Documentation
//! Runs the sim on loopback, for trying a client by hand.
//!
//! `hafas-sim [PORT]` prints the base URLs of both versions and serves until
//! standard input ends (Ctrl-D), so the process exits normally.

use tokio::io::AsyncReadExt;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let port = match std::env::args().nth(1).map(|port| port.parse::<u16>()) {
        None => 0,
        Some(Ok(port)) => port,
        Some(Err(error)) => {
            eprintln!("hafas-sim: invalid port: {error}");
            std::process::exit(2);
        }
    };
    let sim = hafas_sim::Sim::start_at(port).await;
    println!("2.39: {}", sim.base_url());
    println!("2.52: {}", sim.latest_url());
    println!("access key: {}", hafas_sim::ACCESS_ID);
    let mut sink = Vec::new();
    // Errors of stdin end the sim the same way.
    let _ = tokio::io::stdin().read_to_end(&mut sink).await;
}