From cb225ae7de3f0d870667f2e4dc3507eede98fe8f Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 30 Oct 2024 01:56:47 +0100 Subject: [PATCH] feat: load dotenv --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6930f3d..0bb8a5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dyn-clone" version = "1.0.17" @@ -820,6 +826,7 @@ dependencies = [ "base64", "chrono", "clap", + "dotenv", "http", "indexmap", "jaq-interpret", diff --git a/Cargo.toml b/Cargo.toml index 6bc53c5..2558eda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ edition = "2021" base64 = "0.22.1" chrono = "0.4" clap = { version = "4.5", features = ["derive"] } +dotenv = "0.15" http = "1.1.0" indexmap = { version = "2.6", features = ["serde"] } jaq-interpret = "1.5" diff --git a/src/main.rs b/src/main.rs index 6b1cd58..d2a0eb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,10 @@ struct PostWomanArgs { #[arg(short, long, default_value = "postwoman.toml")] collection: std::path::PathBuf, + /// environment (.env) to load + #[arg(short, long, default_value = "")] + env: String, + /// action to run #[clap(subcommand)] action: Option, @@ -86,6 +90,12 @@ fn main() { }, PostWomanActions::Run { query, parallel, debug, dry_run } => { + eprintln!("~@ {APP_USER_AGENT}"); + + if let Err(e) = dotenv::from_filename(format!("{}.env", args.env)) { + eprintln!(" ! error loading env file: {e}"); + } + // note that if you remove this test, there's another .expect() below you need to manage too! let filter = match regex::Regex::new(query) { Ok(regex) => regex, @@ -114,7 +124,6 @@ fn main() { } }; - eprintln!("~@ {APP_USER_AGENT}"); if multi_thread { tokio::runtime::Builder::new_multi_thread() .enable_all()