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

trigger-builder-herokuish-docker-args() {
  declare desc="builder-herokuish docker-args plugin trigger"
  declare trigger="docker-args"
  declare APP="$1"
  local STDIN DOKKU_APP_TYPE DOKKU_APP_USER

  STDIN=$(cat)
  DOKKU_APP_TYPE="$(plugn trigger builder-get-property "$APP" "detected" || true)"
  DOKKU_APP_USER="$(config_get "$APP" DOKKU_APP_USER || true)"
  DOKKU_APP_USER="${DOKKU_APP_USER:="herokuishuser"}"

  if [[ "$DOKKU_APP_TYPE" == "herokuish" ]]; then
    local docker_args="$STDIN --env=USER=${DOKKU_APP_USER}"
  else
    local docker_args="$STDIN"
  fi

  echo -n "$docker_args"
}

trigger-builder-herokuish-docker-args "$@"
