feat: load dotenv

This commit is contained in:
əlemi 2024-10-30 01:56:47 +01:00
parent f12de31125
commit cb225ae7de
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 18 additions and 1 deletions

7
Cargo.lock generated
View file

@ -260,6 +260,12 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "dyn-clone" name = "dyn-clone"
version = "1.0.17" version = "1.0.17"
@ -820,6 +826,7 @@ dependencies = [
"base64", "base64",
"chrono", "chrono",
"clap", "clap",
"dotenv",
"http", "http",
"indexmap", "indexmap",
"jaq-interpret", "jaq-interpret",

View file

@ -13,6 +13,7 @@ edition = "2021"
base64 = "0.22.1" base64 = "0.22.1"
chrono = "0.4" chrono = "0.4"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
dotenv = "0.15"
http = "1.1.0" http = "1.1.0"
indexmap = { version = "2.6", features = ["serde"] } indexmap = { version = "2.6", features = ["serde"] }
jaq-interpret = "1.5" jaq-interpret = "1.5"

View file

@ -23,6 +23,10 @@ struct PostWomanArgs {
#[arg(short, long, default_value = "postwoman.toml")] #[arg(short, long, default_value = "postwoman.toml")]
collection: std::path::PathBuf, collection: std::path::PathBuf,
/// environment (.env) to load
#[arg(short, long, default_value = "")]
env: String,
/// action to run /// action to run
#[clap(subcommand)] #[clap(subcommand)]
action: Option<PostWomanActions>, action: Option<PostWomanActions>,
@ -86,6 +90,12 @@ fn main() {
}, },
PostWomanActions::Run { query, parallel, debug, dry_run } => { 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! // note that if you remove this test, there's another .expect() below you need to manage too!
let filter = match regex::Regex::new(query) { let filter = match regex::Regex::new(query) {
Ok(regex) => regex, Ok(regex) => regex,
@ -114,7 +124,6 @@ fn main() {
} }
}; };
eprintln!("~@ {APP_USER_AGENT}");
if multi_thread { if multi_thread {
tokio::runtime::Builder::new_multi_thread() tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()