Skip to content

Commit

Permalink
feat: work_dir from env
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jan 10, 2025
1 parent 0e12314 commit 10027a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crates/cdk-mintd/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 12 additions & 5 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 10027a3

Please sign in to comment.