iocaine/src/main.rs
Gergely Nagy e3306e7998
Slight environment variable adjustment
When configuring iocaine via environment variables, sections and
settings were separated by two underlines, but the `IOCAINE_` prefix
only had one. This felt weird, so now iocaine supports an `IOCAINE__`
prefix too, and keeps recognizing the old one too.

Documentation and examples updated to use the new naming. No mention of
the backwards compatibility - I'll just silently support that.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
2025-01-25 02:16:06 +01:00

47 lines
1.5 KiB
Rust

// 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;
mod iocaine;
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(())
}