iocaine 1.0.0

The deadliest poison known to AI
Documentation
// SPDX-FileCopyrightText: 2025 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: MIT

use anyhow::Result;
use clap::Parser;
use figment::{
    providers::{Env, Format, Toml},
    Figment,
};
use figment_file_provider_adapter::FileAdapter;

use iocaine::{app::Iocaine, cli, config::Config};

#[tokio::main]
async fn main() -> Result<()> {
    #[cfg(all(feature = "tokio-console", tokio_unstable))]
    console_subscriber::init();
    #[cfg(all(feature = "tokio-console", not(tokio_unstable)))]
    compile_error!("`tokio-console` requires manually enabling the `--cfg tokio_unstable` rust flag during compilation!");

    #[cfg(not(feature = "tokio-console"))]
    tracing_subscriber::fmt::init();

    let args = cli::Args::parse();
    tracing::debug!(config_file = &args.config_file, "loading configuration");

    let config: Config = Figment::new()
        .merge(FileAdapter::wrap(Env::prefixed("IOCAINE_").split("__")))
        .merge(FileAdapter::wrap(Env::prefixed("IOCAINE__").split("__")))
        .merge(FileAdapter::wrap(Toml::file(&args.config_file)))
        .extract()
        .unwrap_or_else(|err| {
            tracing::error!(err = format!("{}", err), "Failed to load configuration");
            panic!(
                "Failed to load configuration from {} (and environment variables): {}",
                &args.config_file, err
            );
        });

    let app = Iocaine::new(config)?;
    app.run().await?;

    Ok(())
}