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

domains_main_cmd() {
  declare desc="print app domains"
  local cmd="domains"
  local APP="$2"

  if [[ "$(is_global_vhost_enabled)" == "true" ]]; then
    dokku_log_info2_quiet "Global Domain Name"
    get_global_vhosts
  fi
  if [[ -n "$APP" ]]; then
    verify_app_name "$APP"
    if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
      dokku_log_info2_quiet "$APP Domain Names"
      get_app_domains "$APP"
    else
      dokku_log_fail "No domain names set for $APP"
    fi
  fi
}

domains_main_cmd "$@"
