From 10027a3057a0a39802183a4a3864ed327c707ae2 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Fri, 10 Jan 2025 16:24:44 +0000 Subject: [PATCH] feat: work_dir from env --- crates/cdk-mintd/src/env_vars.rs | 2 ++ crates/cdk-mintd/src/main.rs | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/cdk-mintd/src/env_vars.rs b/crates/cdk-mintd/src/env_vars.rs index 3147e069c..27b815b01 100644 --- a/crates/cdk-mintd/src/env_vars.rs +++ b/crates/cdk-mintd/src/env_vars.rs @@ -10,6 +10,8 @@ use crate::config::{ Phoenixd, Settings, Strike, }; +pub const ENV_WORK_DIR: &str = "CDK_MINTD_WORK_DIR"; + pub const DATABASE_ENV_VAR: &str = "CDK_MINTD_DATABASE"; pub const ENV_URL: &str = "CDK_MINTD_URL"; pub const ENV_LISTEN_HOST: &str = "CDK_MINTD_LISTEN_HOST"; diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index 8c17377f6..fc59cfe47 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -4,6 +4,7 @@ #![warn(rustdoc::bare_urls)] use std::collections::HashMap; +use std::env; use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; @@ -25,6 +26,7 @@ use cdk::types::LnKey; use cdk_axum::cache::HttpCache; use cdk_mintd::cli::CLIArgs; use cdk_mintd::config::{self, DatabaseEngine, LnBackend}; +use cdk_mintd::env_vars::ENV_WORK_DIR; use cdk_mintd::setup::LnBackendSetup; use cdk_redb::MintRedbDatabase; use cdk_sqlite::MintSqliteDatabase; @@ -54,19 +56,24 @@ async fn main() -> anyhow::Result<()> { let args = CLIArgs::parse(); - let work_dir = match args.work_dir { - Some(w) => w, - None => work_dir()?, + let work_dir = if let Some(work_dir) = args.work_dir { + tracing::info!("Using work dir from cmd arg"); + work_dir.into() + } else if let Ok(env_work_dir) = env::var(ENV_WORK_DIR) { + tracing::info!("Using work dir from env var"); + env_work_dir.into() + } else { + work_dir()? }; + tracing::info!("Using work dir: {}", work_dir.display()); + // get config file name from args let config_file_arg = match args.config { Some(c) => c, None => work_dir.join("config.toml"), }; - tracing::info!("Using work dir: {}", work_dir.display()); - let mut mint_builder = MintBuilder::new(); let mut settings = if config_file_arg.exists() {