Skip to content

Commit

Permalink
Fix .env.toml paths (#15645)
Browse files Browse the repository at this point in the history
This PR fixes the `.env.toml` paths, since we inadvertently broke them
in #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
  • Loading branch information
maxdeviant authored Aug 1, 2024
1 parent 4bfb8fd commit 60127f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/collab/src/bin/dotenv.rs
Original file line number Diff line number Diff line change
@@ -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(())
Expand Down
11 changes: 7 additions & 4 deletions crates/collab/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use anyhow::{anyhow, Result};
use std::fs;
use std::path::Path;

pub fn get_dotenv_vars(current_dir: impl AsRef<Path>) -> Result<Vec<(String, String)>> {
let current_dir = current_dir.as_ref();

pub fn get_dotenv_vars() -> Result<Vec<(String, String)>> {
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)?;
}

Ok(vars)
}

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(())
Expand Down

0 comments on commit 60127f2

Please sign in to comment.