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
Check presence of env-vars #843
Labels
Comments
Sounds good. It would something like this: env_vars_required() {
for var in "$@"; do
if [[ -z ${!var} ]]; then
echo "env var $var is required and missing" >&2
return 1
fi
done
} |
Thanks - I reworked it slightly to 1) catch non-exported/empty variables (which we had a few of 😳 ) and 2) to not exit and log all missing variables. env_vars_required() {
for var in "$@"; do
if ! env | grep -q '^'"$var"'=\w'; then
log_error "env var $var is required but missing/empty"
fi
done
} @zimbatm Would it be something to include in the stdlib? If so, I'll happily submit a PR. |
Yeah, something like that could be nice to have. Here is an even better version:
env_vars_required() {
ret=0
for var in "$@"; do
if [[ -z ${!var:-} ]]; then
log_error "env var $var is required but missing/empty"
ret=1
fi
done
return "$ret"
} |
eval
added a commit
to eval/direnv
that referenced
this issue
Dec 29, 2021
Check presence of env vars: env_vars_required SOME_TOKEN Fixes direnv#843
eval
added a commit
to eval/direnv
that referenced
this issue
Dec 29, 2021
Check presence of env vars: env_vars_required SOME_TOKEN Fixes direnv#843
eval
added a commit
to eval/direnv
that referenced
this issue
Dec 29, 2021
Check presence of env vars: env_vars_required SOME_TOKEN Fixes direnv#843
zimbatm
pushed a commit
that referenced
this issue
Dec 29, 2021
Check presence of env vars: env_vars_required SOME_TOKEN Fixes #843
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I often use the following setup when working with teams:
.envrc.local
git-ignored (originating from.envrc.local.example
) and.envrc
in git containing:So DATABASE_URL is a variable that is straightforward: we can provide a sane default value and if needed it can be locally overridden.
There are also variables that our project requires but 1) for which we cannot provide plausible defaults (vary too much per developer) or 2) that are secrets which we won't include in
.envrc
.Describe the solution you'd like
For these types of variables it would be nice to have the possibility to check their presence and warn if absent:
The text was updated successfully, but these errors were encountered: