Enhance .env file handling and validation in scripts

This commit is contained in:
Eugene Rakhmatulin
2026-03-25 23:16:56 -07:00
parent 8b7c02aa25
commit c2fe579ccc
3 changed files with 42 additions and 53 deletions

View File

@@ -4,11 +4,19 @@
# This is called early so that DOTENV_* variables are available to all functions
load_env_if_exists() {
local env_file="${CONFIG_FILE:-}"
local config_explicit="${CONFIG_FILE_SET:-false}"
# If CONFIG_FILE is not set, check default location
if [[ -z "$env_file" ]]; then
local script_dir="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
env_file="$script_dir/.env"
config_explicit="false"
fi
# Validate config file exists if explicitly specified
if [[ "$config_explicit" == "true" ]] && [[ ! -f "$env_file" ]]; then
echo "Error: Config file not found: $env_file"
exit 1
fi
if [[ -f "$env_file" ]]; then