usaidwat 4.0.0

Answers the age-old question, "Where does a Redditor comment the most?"
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2025 Michael Dippery <michael@monkey-robot.com>

use clap::Parser;
use hypertyper::HttpError;
use reqwest::StatusCode;
use std::process;
use usaidwat::cli::{Config, Error, Runner};

fn die(error_code: i32, message: &str) {
    eprintln!("{}", message);
    process::exit(error_code);
}

fn dispatch_err(username: &str, err: &Error) {
    let message = match err {
        Error::Service(HttpError::Http(StatusCode::NOT_FOUND)) => {
            format!("no such user: {username}")
        }
        _ => err.to_string(),
    };
    die(67, &message)
}

#[tokio::main]
async fn main() {
    let config = Config::parse();
    let username = config.username();
    env_logger::builder()
        .filter_level(config.verbosity().into())
        .init();
    match Runner::new(config).await {
        Ok(runner) => {
            if let Err(message) = runner.run().await {
                die(1, &message)
            }
        }
        Err(err) => dispatch_err(&username, &err),
    }
}