Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steezeburger/0e83f65a86e88f27b08dbee3f00443c5 to your computer and use it in GitHub Desktop.
Save steezeburger/0e83f65a86e88f27b08dbee3f00443c5 to your computer and use it in GitHub Desktop.
Hierarchical configuration with printlns for auditing purposes.
use std::time::Duration;
use clap::Parser;
use color_eyre::eyre::Result;
use figment::{providers::{Env, Format, Serialized, Toml}, Figment, Provider};
use tokio::{signal, time};
use crate::alert::Alert;
use crate::cli::Cli;
use crate::config::Config;
use crate::driver::{spawn, DriverCommand};
pub(crate) mod alert;
pub(crate) mod cli;
pub(crate) mod config;
pub(crate) mod driver;
pub(crate) mod executor;
pub(crate) mod logger;
pub(crate) mod reader;
pub async fn run() -> Result<()> {
// logs
logger::initialize();
// hierarchical config. cli args override Envars which override toml config values
let mut figment = Figment::new();
if let toml_config = Toml::file("ConductorConfig.toml") {
println!("{:#?}", toml_config.data());
figment = figment.merge(toml_config);
}
if let env_config = Env::prefixed("ASTRIA_") {
println!("{:#?}", env_config.data());
figment = figment.merge(env_config);
}
if let cli_config = Serialized::defaults(Cli::parse()) {
println!("{:#?}", cli_config.data());
figment = figment.merge(cli_config);
}
let conf: Config = figment.extract()?;
log::info!("Using node at {}", conf.celestia_node_url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment