Skip to content

Commit

Permalink
remove repeated env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
SaswatPadhi committed Nov 11, 2024
1 parent 6da3384 commit c58f0f1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions comp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ OPTION_PORTS=""

__append_env_from () {
if [ -f "$1" ] ; then
local script_file="${1/#./$_CUR_COMP_}"
echo -n " ${script_file#"$SELF_DIR"/}"
if set -a && source .env && "$1" > .env.add ; then
cat .env.add >> .env ; rm .env.add
else
local script_file="${1/#./$_CUR_COMP_}"
echo "'${script_file#"$SELF_DIR"/}' FAILED!" ; return 1
echo " ${_fg_red_}${_bold_}FAILED!${_normal_}" ; return 1
fi
fi
}
Expand Down Expand Up @@ -103,7 +104,7 @@ __gen_env () {
[ ! -f .env ] || [ "$FLAG_SKIP_REGENERATE" != "yes" ] || return 0
rm -rf .env

printf "[*] Generating '.env': "
printf "[*] Generating '.env':"
cp "$SELF_DIR/static.global.env" .env || return 1
if [ "$FLAG_SKIP_OVERRIDES" != "yes" ] && [ -f "$SELF_DIR/static.global.override.env" ] ; then
cat "$SELF_DIR/static.global.override.env" >> .env || return 1
Expand All @@ -113,15 +114,19 @@ __gen_env () {
[ "$FLAG_SKIP_OVERRIDES" = "yes" ] || \
__append_env_from "$SELF_DIR/dynamic.global.override.env.sh" || return 1

[ ! -f "./static.env" ] || cat "./static.env" >> .env || return 1
[ ! -f "static.env" ] || cat "static.env" >> .env || return 1
[ "$FLAG_SKIP_OVERRIDES" = "yes" ] || \
[ ! -f "./static.override.env" ] || cat "./static.override.env" >> .env || return 1
[ ! -f "static.override.env" ] || cat "static.override.env" >> .env || return 1

__append_env_from "./dynamic.env.sh" || return 1
[ "$FLAG_SKIP_OVERRIDES" = "yes" ] || \
__append_env_from "./dynamic.override.env.sh" || return 1

echo OK
env -i bash --norc --noprofile -c "set -a ; source .env ; env" \
| sed 's;^\(_\|PWD\|SHLVL\)=.*$;;g' | grep . > .env.new
mv .env.new .env

echo " ${_fg_green_}DONE${_normal_}"
}

__gen_templates () {
Expand Down

0 comments on commit c58f0f1

Please sign in to comment.