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

cmd-events-list() {
  declare desc="lists enabled events"
  declare cmd="events:list"
  [[ "$1" == "$cmd" ]] && shift 1

  local PLUGIN_DIR="$(dirname "$0")/.."
  local logged hook

  if [[ "$DOKKU_EVENTS" ]]; then
    logged="$(find "$PLUGIN_DIR" -type l -printf '%f\n' 2>/dev/null | sort -n)"
    dokku_col_log_info2_quiet "Events currently logged"

    for hook in $logged; do
      if [[ "$hook" == "help-functions" ]]; then
        continue
      fi
      dokku_col_log_msg "$hook"
    done
  else
    dokku_log_warn "Events logger disabled"
  fi
}

cmd-events-list "$@"
