Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source_up_if_exists: A strict_env compatible version of source_up #921

Merged
merged 4 commits into from
Apr 14, 2022

Conversation

jfly
Copy link
Contributor

@jfly jfly commented Apr 8, 2022

This fixes #913

While I was in here, I opted to make the existing source_up script log
explicitly when it can't find a file. I think that's useful both with
strict_env enabled and disabled.

This fixes direnv#913

While I was in here, I opted to make the existing `source_up` script log
explicitly when it can't find a file. I think that's useful both with
strict_env enabled and disabled.
Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

There are two minor suggestions. If you could also extend the stdlib docs in the man folder that would be perfect.

stdlib.sh Outdated Show resolved Hide resolved
stdlib.sh Outdated
Comment on lines 443 to 447
local envrc file=${1:-.envrc}
envrc=$(cd .. && (find_up "$file" || true))
if [[ -n $envrc ]]; then
source_env "$envrc"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local envrc file=${1:-.envrc}
envrc=$(cd .. && (find_up "$file" || true))
if [[ -n $envrc ]]; then
source_env "$envrc"
fi
source_up "${1:-}" || true

With the above change it becomes possible to deduplicate the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works, but with my change to source_up, it means you get a red "No ancestor .envrc found" message even though this function still succeeds.

I've tweaked things around a little bit to try to DRY this up. I'm honestly not sure if it's better or worse. What do you think, @zimbatm?

jfly and others added 3 commits April 11, 2022 16:09
Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I pushed a small fixup and it's good to go

@zimbatm zimbatm merged commit c965ba0 into direnv:master Apr 14, 2022
@jfly
Copy link
Contributor Author

jfly commented Apr 14, 2022

Thanks, @zimbatm!

@ssbarnea
Copy link

Thanks for implementing this feature, I was looking for a way to avoid a confusing warning.

@gertvdijk gertvdijk mentioned this pull request Jul 13, 2022
@gertvdijk
Copy link
Contributor

gertvdijk commented Jul 13, 2022

Hi @zimbatm@jfly; I just noticed you edited the generated file man/direnv-stdlib.1 instead of the source file man/direnv-stdlib.1.md for this change. Wanted to let you know for the next time.

Updated here: f58196a

And perhaps the maintainer could add a CI change to validate that the docs source->generated files are up to date (if the generated ones need to be in the repository at all...).

update: oops, mis-tagged the author.

@jfly
Copy link
Contributor Author

jfly commented Jul 13, 2022

Oh, that's on me, not @zimbatm, sorry! I agree that this feels like an unnecessary footgun: could we get the generated files out of version control?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Provide a strict_env compatible version of source_up
4 participants