#!/bin/sh
# Installs the excyst command: https://excyst.com
# Uses uv if present, then pipx, then pip --user. Needs Python 3.11 or newer (uv fetches one if needed).
set -eu
WHEEL="https://excyst.com/dl/excyst-0.2.1-py3-none-any.whl"
say() { printf '%s\n' "$*"; }
if command -v uv >/dev/null 2>&1; then
  say "installing excyst with uv"
  uv tool install --force "$WHEEL"
elif command -v pipx >/dev/null 2>&1; then
  say "installing excyst with pipx"
  pipx install --force "$WHEEL"
elif command -v python3 >/dev/null 2>&1 && python3 -c 'import sys; sys.exit(sys.version_info < (3, 11))'; then
  say "installing excyst with pip --user"
  if ! python3 -m pip install --user --upgrade "$WHEEL"; then
    say ""
    say "pip could not install into this Python (it may be managed by your system)."
    say "Install uv (https://docs.astral.sh/uv/) or pipx, then run this again."
    exit 1
  fi
else
  say "excyst needs Python 3.11 or newer. The easiest route is uv: https://docs.astral.sh/uv/"
  say "then:  uv tool install $WHEEL"
  exit 1
fi
say ""
say "done. Try:  excyst tour"
say "if the command is not found, open a new terminal (uv: run  uv tool update-shell  once)."
