#!/usr/bin/env bash
[[ " help help:help run:help trace:help url:help urls:help version:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x

case "$1" in
  help | run:help | trace:help | url:help | urls:help | version:help)
    [[ $(echo "$1" | sed '/.*:help/!d') ]] && help_topic="${1%\:help}"
    help_content_func() {
      declare desc="return standard plugin help content"
      cat <<help_content
    run <app> <cmd>, Run a command in a new container using the current application image
    trace [on/off], Enable dokku tracing
    url <app>, Show the first URL for an application (compatibility)
    urls <app>, Show all URLs for an application
    version , Print dokku's version
    help , Print the list of commands
help_content
    }

    if [[ $help_topic ]]; then
      help_content_func | sed "/^\s*$help_topic\s/!d" | sort | sed '/^.*:/d' | column -c2 -t -s,
    else
      help_content_func
    fi
    ;;

  *)
    exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
    ;;

esac
