#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_PATH/common/functions"

config_export() {
  local CONFIG_TYPE="$1"
  local APP="$2"
  local ENV_FILE="$DOKKU_ROOT/$APP/ENV"

  [[ $CONFIG_TYPE == "global" ]] && ENV_FILE="$DOKKU_ROOT/ENV"
  [[ ! -f $ENV_FILE ]] && return 0
  [[ ! -s $ENV_FILE ]] && return 0

  VARS=$(grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" $ENV_FILE | cut -d" " -f2-)
  echo "$VARS" | awk '{print "export " $0}'
  return 0
}
