#!/usr/bin/env bash
[[ " nginx:build-config nginx:access-logs nginx:error-logs help nginx:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions"

case "$1" in
  nginx:build-config)
    [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
    nginx_build_config "$2"
  ;;

  nginx:access-logs|nginx:error-logs)
    [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
    nginx_logs "$@"
  ;;

  help | nginx:help)
    cat<<EOF
    nginx:build-config <app>, (Re)builds nginx config for given app
    nginx:access-logs <app> [-t], Show the nginx access logs for an application (-t follows)
    nginx:error-logs <app> [-t], Show the nginx error logs for an application (-t follows)
EOF
  ;;

  *)
    exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
  ;;

esac
