#!/usr/bin/env bash
# Run juanita from this checkout for development, using fades.
#
# fades creates/reuses a managed virtualenv and installs this project in
# editable mode (`-e .`), so your local changes under src/ are picked up on the
# next run with no reinstall. The `-d requests` is only there to trigger fades'
# install step (requests is a real dependency; `-e .` pulls it in anyway).
#
# Usage:
#   bin/run_dev --dry-run https://youtu.be/VIDEO_ID
#   bin/run_dev init
#   bin/run_dev --help
#
# Add a new third-party dependency to pyproject.toml? Force a fresh venv so it
# gets installed, e.g.: FADES_REBUILD=1 bin/run_dev ...
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

if ! command -v fades >/dev/null 2>&1; then
    echo "error: fades is not installed. See https://github.com/PyAr/fades" >&2
    exit 1
fi

pip_options="-e ."
if [[ "${FADES_REBUILD:-}" == "1" ]]; then
    # --force-reinstall makes pip rebuild the editable install in the venv.
    pip_options="-e . --force-reinstall"
fi

exec fades -d requests --pip-options="$pip_options" -x juanita -- "$@"
