Skip to content

Commit

Permalink
env-file: add dotenv paths to watch files (#1615)
Browse files Browse the repository at this point in the history
Fixes #1613
  • Loading branch information
jdx committed Feb 5, 2024
1 parent 6e8a97f commit d15ea44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ impl Config {
self.env_with_sources.get_or_try_init(|| {
let mut env = self.env_results()?.env.clone();
let settings = Settings::get();
if let Some(env_file) = &settings.env_file {
match dotenvy::from_filename_iter(env_file) {
for env_file in settings.env_files() {
match dotenvy::from_path_iter(&env_file) {
Ok(iter) => {
for item in iter {
let (k, v) = item.unwrap_or_else(|err| {
Expand Down Expand Up @@ -331,12 +331,13 @@ impl Config {
EnvResults::resolve(&env::PRISTINE_ENV, entries)
}

pub fn watch_files(&self) -> eyre::Result<BTreeSet<&Path>> {
pub fn watch_files(&self) -> eyre::Result<BTreeSet<PathBuf>> {
Ok(self
.config_files
.keys()
.chain(self.env_results()?.env_files.iter())
.map(|p| p.as_path())
.map(|p| p.to_path_buf())
.chain(self.env_results()?.env_files.clone())
.chain(Settings::get().env_files())
.collect())
}

Expand Down
14 changes: 14 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde::ser::Error;
use serde_derive::{Deserialize, Serialize};

use crate::config::{system_config_files, DEFAULT_CONFIG_FILENAMES};
use crate::file::FindUp;
use crate::{config, dirs, env, file};

#[derive(Config, Default, Debug, Clone, Serialize)]
Expand Down Expand Up @@ -355,6 +356,19 @@ impl Settings {
})
}

pub fn env_files(&self) -> Vec<PathBuf> {
let mut files = vec![];
if let Some(cwd) = &*dirs::CWD {
if let Some(env_file) = &self.env_file {
let env_file = env_file.to_string_lossy().to_string();
for p in FindUp::new(cwd, &[env_file]) {
files.push(p);
}
}
}
files.into_iter().rev().collect()
}

pub fn as_dict(&self) -> eyre::Result<toml::Table> {
Ok(self.to_string().parse()?)
}
Expand Down

0 comments on commit d15ea44

Please sign in to comment.