From 60127f2a8db4e2db3c6f9b0503229e11a06e5999 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 1 Aug 2024 15:43:29 -0400 Subject: [PATCH] Fix `.env.toml` paths (#15645) This PR fixes the `.env.toml` paths, since we inadvertently broke them in https://github.com/zed-industries/zed/pull/15557. There's likely a better way we can do this, but I wanted to restore the previous behavior, for now. Release Notes: - N/A --- crates/collab/src/bin/dotenv.rs | 2 +- crates/collab/src/env.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/collab/src/bin/dotenv.rs b/crates/collab/src/bin/dotenv.rs index b2f5af9b39..6cd7c1f289 100644 --- a/crates/collab/src/bin/dotenv.rs +++ b/crates/collab/src/bin/dotenv.rs @@ -1,7 +1,7 @@ use collab::env::get_dotenv_vars; fn main() -> anyhow::Result<()> { - for (key, value) in get_dotenv_vars()? { + for (key, value) in get_dotenv_vars(".")? { println!("export {}=\"{}\"", key, value); } Ok(()) diff --git a/crates/collab/src/env.rs b/crates/collab/src/env.rs index f5e316bb4a..bdbb4819fb 100644 --- a/crates/collab/src/env.rs +++ b/crates/collab/src/env.rs @@ -1,14 +1,17 @@ use anyhow::{anyhow, Result}; use std::fs; +use std::path::Path; + +pub fn get_dotenv_vars(current_dir: impl AsRef) -> Result> { + let current_dir = current_dir.as_ref(); -pub fn get_dotenv_vars() -> Result> { let mut vars = Vec::new(); - let env_content = fs::read_to_string("./crates/collab/.env.toml") + let env_content = fs::read_to_string(current_dir.join(".env.toml")) .map_err(|_| anyhow!("no .env.toml file found"))?; add_vars(env_content, &mut vars)?; - if let Ok(secret_content) = fs::read_to_string("./crates/collab/.env.secret.toml") { + if let Ok(secret_content) = fs::read_to_string(current_dir.join(".env.secret.toml")) { add_vars(secret_content, &mut vars)?; } @@ -16,7 +19,7 @@ pub fn get_dotenv_vars() -> Result> { } pub fn load_dotenv() -> Result<()> { - for (key, value) in get_dotenv_vars()? { + for (key, value) in get_dotenv_vars("./crates/collab")? { std::env::set_var(key, value); } Ok(())