#!/usr/bin/env bash
[[ " help help:help ls: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|ls: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
    ls , Pretty listing of deployed applications and containers
    run <app> <cmd>, Run a command in the environment of an application
    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
