#!/usr/bin/env bash
set -e
set -u
set -o pipefail

while getopts d OPTION "$@"; do
    case $OPTION in
	d)
	    set -x
	    ;;
    esac
done

PROJECT_ROOT=$(dirname "${BASH_SOURCE[0]}")
cd "${PROJECT_ROOT}"

echo "Compiling and computing classpath (May take a while)"
# Sadly even with the --quiet option Gradle (or some component of)
# will print the number of warnings/errors to stdout if there are
# any.
GRADLE_CLASSPATH="$(gradle :minidns-repl:printClasspath --quiet |\
	tail -n1)"
echo "Classpath computed, starting REPL"

java \
	-ea \
	-Dscala.usejavacp=true \
	-classpath "${GRADLE_CLASSPATH}" \
	ammonite.Main \
	--predef minidns-repl/scala.repl
