#!/bin/bash

# Exit on first failing command.
set -e

# Exit on unset variable.
set -u

# Echo commands
set -x

# Change directory to repository root.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."

# Install modd if it's not present.
MODD_PATH="$(go env GOPATH)/bin/modd"
readonly MODD_PATH
if [[ ! -f "${MODD_PATH}" ]]; then
    go get github.com/cortesi/modd/cmd/modd
    go install github.com/cortesi/modd/cmd/modd
fi

# Run modd for hot reloading.
"${MODD_PATH}"