#!/usr/bin/env bash

set -e

[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en .stack-work.lock "$0" "$@" || :

unset HOST
export DETAILED_LOGGING=true
export LOG_ALL=true
export DUMMY_LOGIN=true

move-back() {
    mv -v .stack-work .stack-work-ghci
    [[ -d .stack-work-build ]] && mv -v .stack-work-build .stack-work
}

if [[ -d .stack-work-ghci ]]; then
    [[ -d .stack-work ]] && mv -v .stack-work .stack-work-build
    mv -v .stack-work-ghci .stack-work
    trap move-back EXIT
fi

stack ghci --flag uniworx:dev --flag uniworx:library-only ${@:-uniworx:lib}
