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

cmd-events-default() {
  declare desc="shows contents of dokku events log"
  declare cmd="events"
  [[ "$1" == "$cmd" ]] && shift 1
  declare TAIL="$1"

  if [[ -f $DOKKU_EVENTS_LOGFILE ]]; then
    if [[ "$TAIL" == "-t" ]]; then
      tail -F "$DOKKU_EVENTS_LOGFILE"
    else
      tail -n 100 "$DOKKU_EVENTS_LOGFILE"
    fi
  fi
}

cmd-events-default "$@"
