#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
#
# llamachat - a small native chat client for a local llama.cpp router
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
"""Launcher. Symlink this into a directory on your PATH.

PySide6 usually lives in a virtualenv rather than the system Python, so this
re-executes itself with the venv interpreter when it finds one. Set
LLAMACHAT_PYTHON to point at a specific interpreter, otherwise the venv
beside the checkout and the default location are tried in turn.
"""

import sys
from pathlib import Path

# Resolve through the symlink so the package is found next to the real file.
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))

import llamachat_venv  # noqa: E402

# The control commands do not need Qt, so only pay for the handover when a
# command that builds a window is about to run.
_NO_QT = {"--toggle", "--show", "--hide", "--ping", "--quit", "--version",
          "--help", "-h"}
if not _NO_QT & set(sys.argv[1:]):
    llamachat_venv.reexec(__file__)

from llamachat.__main__ import main  # noqa: E402

if __name__ == "__main__":
    sys.exit(main())
