#!/usr/bin/env 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}/.."

GOBIN="$(go env GOBIN)"
if [[ -z "${GOBIN}" ]]; then
  GOBIN="$(go env GOPATH)/bin"
fi
readonly GOBIN

# Install air if it's not present.
AIR_PATH="${GOBIN}/air"
readonly AIR_PATH
readonly AIR_VERSION="v1.67.4"
if [[ ! -f "${AIR_PATH}" ]]; then
  CGO_ENABLED=0 go install "github.com/air-verse/air@${AIR_VERSION}"
fi

# Run air for hot reloading.
"${AIR_PATH}"
