yage
eaefc99774
===================================================================== Subscwrypts + Environment Inheritance --- Release Notes ------------------------ - added support for environment inheritance - added support for arbitrarily nested scripts (subscwrypts) - added support for CI mode - improved modularity of zsh/utils module - refactored to move some data from ~/.config/scwrypts to ~/.local/share/scwrypts - refactored various scripts to use new subscwrypt api --- New Scripts -------------------------- zsh ) - db/interactive/postgres - aws/rds/interactive-login
38 lines
753 B
Bash
38 lines
753 B
Bash
__CHECK_REQUIRED_ENV() {
|
|
local VAR ERROR=0
|
|
for VAR in $*; do __CHECK_ENV_VAR $VAR || ((ERROR+=1)); done
|
|
return $ERROR
|
|
}
|
|
|
|
__CHECK_ENV_VAR() {
|
|
local NAME="$1"
|
|
[ ! $NAME ] && return 1
|
|
|
|
local OPTIONAL="$2"
|
|
local DEFAULT_VALUE="$3"
|
|
|
|
local VALUE=$(eval echo '$'$NAME)
|
|
[ $VALUE ] && return 0
|
|
|
|
|
|
[ $__SCWRYPT ] && {
|
|
# scwrypts exclusive (missing vars staged in env.template)
|
|
local LINE="export $NAME="
|
|
|
|
grep -q -- "^$LINE" "$__ENV_TEMPLATE" || {
|
|
__STATUS 'staging new variable in template'
|
|
|
|
echo "$LINE" >> "$__ENV_TEMPLATE" \
|
|
&& __RUN_SCWRYPT zsh/scwrypts/environment/synchronize -- --no-prompt
|
|
}
|
|
}
|
|
|
|
[ $OPTIONAL ] && {
|
|
[ $DEFAULT_VALUE ] && $NAME="$DEFAULT_VALUE"
|
|
return 0
|
|
} || {
|
|
__ERROR "'$NAME' required"
|
|
return 1
|
|
}
|
|
}
|