#!/usr/bin/env python3

import sys
import os

# Find the main infragpt package
try:
    import infragpt
except ImportError:
    # Add parent directory to path if running from source
    sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    import infragpt

from infragpt.main import cli, main

if __name__ == "__main__":
    # Check if we're using the `--` special form to pass everything after as a prompt
    if len(sys.argv) > 1 and sys.argv[1] == "--":
        # Special case for "infragpt -- text"
        prompt = sys.argv[2:]
        sys.argv = [sys.argv[0]]  # Reset sys.argv
        main(prompt=prompt)
    else:
        # Normal CLI handling
        cli()