#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

case "$1" in
  help | google-auth:help)
    help_content() {
      cat <<help_content
    google-auth:configure [options], Configure the shared Google OAuth service (run once)
    google-auth:enable <app>, Require Google sign-in for all requests to <app>
    google-auth:disable <app>, Remove Google sign-in from <app>
    google-auth:exclude <app> <pattern...>, Exempt path prefixes (/path) or regexes (re:^/x) from sign-in
    google-auth:unexclude <app> <pattern...>, Remove previously excluded patterns
    google-auth:report [app], Show global and per-app google-auth status
    google-auth:start, Start the shared auth service container
    google-auth:stop, Stop the shared auth service container
    google-auth:restart, Restart the shared auth service container (picks up config changes)
    google-auth:logs [--tail|-t], Show logs from the shared auth service container
help_content
    }

    if [[ "$1" == "google-auth:help" ]]; then
      echo -e 'Usage: dokku google-auth[:COMMAND]'
      echo ''
      echo 'Put Google OAuth SSO in front of dokku apps.'
      echo ''
      echo 'Commands:'
      help_content | sort | column -c2 -t -s,
    else
      help_content
    fi
    ;;

  *)
    exit "${DOKKU_NOT_IMPLEMENTED_EXIT:-10}"
    ;;
esac
