From 2dd18b71a1d596dee94acab27c24275fbc258216 Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Tue, 17 Dec 2024 13:10:46 +0100 Subject: [PATCH] feat(cli): support env_file --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + crates/rari-cli/main.rs | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1597601f..d0391954 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -920,6 +920,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dtoa" version = "1.0.9" @@ -2595,6 +2601,7 @@ dependencies = [ "clap", "clap-verbosity-flag", "dashmap", + "dotenvy", "rari-deps", "rari-doc", "rari-sitemap", diff --git a/Cargo.toml b/Cargo.toml index 4c97da21..49b9451c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,3 +125,4 @@ clap-verbosity-flag = { version = "3", features = ["tracing"] } tabwriter = "1" axum = "0.7" tokio = "1" +dotenvy = "0.15" diff --git a/crates/rari-cli/main.rs b/crates/rari-cli/main.rs index a210aaa0..a6203975 100644 --- a/crates/rari-cli/main.rs +++ b/crates/rari-cli/main.rs @@ -1,4 +1,6 @@ +use std::borrow::Cow; use std::collections::HashMap; +use std::env; use std::fs::{self, File}; use std::io::{self, BufWriter, Write}; use std::path::PathBuf; @@ -191,6 +193,14 @@ enum Cache { } fn main() -> Result<(), Error> { + if let Ok(env_file) = dotenvy::from_filename( + env::var("DOT_FILE") + .map(Cow::Owned) + .unwrap_or(Cow::Borrowed(".env")) + .as_ref(), + ) { + println!("Using env_file: {}", env_file.display()) + } let cli = Cli::parse(); if !cli.skip_updates { rari_deps::webref_css::update_webref_css(rari_types::globals::data_dir())?;