#!/usr/bin/env bash
# Entry point for the wikitool CLI. Activates the local venv and runs the
# chemenu package as a module so agents can invoke it via a stable path:
#
#   tools/wikitool <command> [options]
#
# Setup (one time):
#   cd tools
#   python3 -m venv .venv
#   .venv/bin/pip install -r requirements.txt
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [ ! -x "$DIR/.venv/bin/python" ]; then
  echo "wikitool: venv not found at $DIR/.venv" >&2
  echo "Run: cd tools && python3 -m venv .venv && .venv/bin/pip install -r requirements.txt" >&2
  exit 1
fi

# Do NOT cd into $DIR: that would resolve relative CLI arguments (e.g.
# --markdown "wiki/Lint Report.md") against tools/ instead of the caller's cwd.
# Add $DIR to PYTHONPATH instead so `chemenu` is importable regardless of
# where this script is invoked from.
export PYTHONPATH="$DIR${PYTHONPATH:+:$PYTHONPATH}"
exec "$DIR/.venv/bin/python" -m chemenu.cli "$@"
