#!/usr/bin/env bash
# nine-hazes-face dev helpers
# Usage:
#   ./dev.sh              build + install on emulator
#   ./dev.sh run          same, plus stream watch logs (Ctrl-C detaches, app keeps running)
#   ./dev.sh log          attach logs only (emulator must be open)
#   ./dev.sh kill         stop the emulator and free the websocket
#   ./dev.sh clean        full rebuild (removes ./build)
set -euo pipefail

cd "$(dirname "$0")"

EMU="emery"

build_install() {
  echo "==> Building ($EMU)..."
  pebble build
  echo "==> Installing to emulator..."
  pebble install --emulator "$EMU"
  echo "==> Done."
}

case "${1:-}" in
  "")
    build_install
    ;;
  run)
    build_install
    echo "==> Streaming logs (Ctrl-C to detach; app keeps running)..."
    pebble logs --emulator "$EMU"
    ;;
  log)
    pebble logs --emulator "$EMU"
    ;;
  kill)
    pebble kill-pebble
    ;;
  clean)
    rm -rf build
    echo "==> ./build removed; next run is a full rebuild."
    ;;
  *)
    echo "Unknown command: $1" >&2
    sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//'
    exit 1
    ;;
esac
