#!/bin/sh
# Managed-venv entry point: isolate Python before any Python code is loaded.
set -eu
launcher=$0
links=0
while [ -L "$launcher" ]; do
    links=$((links + 1))
    if [ "$links" -gt 40 ]; then
        printf '%s\n' 'lexgents: too many launcher symlinks' >&2
        exit 2
    fi
    directory=$(CDPATH= cd -P -- "$(/usr/bin/dirname -- "$launcher")" && pwd -P)
    target=$(/usr/bin/readlink "$launcher")
    case "$target" in
        /*) launcher=$target ;;
        *) launcher=$directory/$target ;;
    esac
done
directory=$(CDPATH= cd -P -- "$(/usr/bin/dirname -- "$launcher")" && pwd -P)
if [ ! -x "$directory/python" ] || [ ! -f "$directory/../pyvenv.cfg" ]; then
    printf '%s\n' 'lexgents: install with uv tool install lexgents-cli, pipx, or pip inside a virtual environment' >&2
    exit 2
fi
exec "$directory/python" -I -m lexgents_cli "$@"
