#!/usr/bin/env python3
import importlib.util
import os
import sys
from pathlib import Path

root = Path(__file__).resolve().parent
sys.path.insert(0, str(root / 'scripts'))
# Child output includes tools that bypass the driver's log helper. Keep machine
# output and redirected streams untouched; the pipe also prevents recursion.
if (sys.stdout.isatty() and sys.stderr.isatty() and '--json' not in sys.argv
        and not os.environ.get('NO_COLOR') and os.environ.get('TERM') != 'dumb'):
    spec = importlib.util.spec_from_file_location('unixnu_build_log', root / 'scripts/build-log.py')
    output = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(output)
    sys.exit(output.relay([sys.executable, str(root / 'unixnu'), *sys.argv[1:]], None, True))
from unixnu.cli import main

main()
