Skip to content

Commit

Permalink
fix: make _.file and _.source optional if the file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 29, 2024
1 parent da6db80 commit feeeff6
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/config/env_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ impl EnvResults {
}
}
EnvDirective::File(input) => {
trust_check(&source)?;
let s = r.parse_template(&ctx, &source, input.to_string_lossy().as_ref())?;
for p in xx::file::glob(normalize_path(&config_root, s.into()))? {
for p in
xx::file::glob(normalize_path(&config_root, s.into())).unwrap_or_default()
{
r.env_files.push(p.clone());
let errfn = || eyre!("failed to parse dotenv file: {}", display_path(&p));
if let Ok(dotenv) = dotenvy::from_path_iter(&p) {
Expand All @@ -229,20 +230,25 @@ impl EnvResults {
}
EnvDirective::Source(input) => {
SETTINGS.ensure_experimental("env._.source")?;
trust_check(&source)?;
let s = r.parse_template(&ctx, &source, input.to_string_lossy().as_ref())?;
for p in xx::file::glob(normalize_path(&config_root, s.into()))? {
r.env_scripts.push(p.clone());
let env_diff = EnvDiff::from_bash_script(&p, env_vars.clone())?;
for p in env_diff.to_patches() {
match p {
EnvDiffOperation::Add(k, v) | EnvDiffOperation::Change(k, v) => {
r.env_remove.remove(&k);
env.insert(k.clone(), (v.clone(), Some(source.clone())));
}
EnvDiffOperation::Remove(k) => {
env.shift_remove(&k);
r.env_remove.insert(k);
if let Ok(s) = r.parse_template(&ctx, &source, input.to_string_lossy().as_ref())
{
for p in xx::file::glob(normalize_path(&config_root, s.into()))
.unwrap_or_default()
{
r.env_scripts.push(p.clone());
let env_diff =
EnvDiff::from_bash_script(&p, env_vars.clone()).unwrap_or_default();
for p in env_diff.to_patches() {
match p {
EnvDiffOperation::Add(k, v)
| EnvDiffOperation::Change(k, v) => {
r.env_remove.remove(&k);
env.insert(k.clone(), (v.clone(), Some(source.clone())));
}
EnvDiffOperation::Remove(k) => {
env.shift_remove(&k);
r.env_remove.insert(k);
}
}
}
}
Expand Down

0 comments on commit feeeff6

Please sign in to comment.