#!/usr/bin/env php
<?php

use StaticPHP\ConsoleApplication;
use StaticPHP\Exception\ExceptionHandler;
use StaticPHP\Exception\SPCException;

if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
    // Current: ./bin (git/project mode)
    require_once dirname(__DIR__) . '/vendor/autoload.php';
} else {
    // Current: ./vendor/crazywhalecc/static-php-cli/bin (composer library mode)
    require_once dirname(__DIR__, 3) . '/autoload.php';
}

// Print deprecation notice on PHP < 8.4, use red and highlight background
if (PHP_VERSION_ID < 80400) {
    echo "\e[43mDeprecation Notice: PHP < 8.4 is deprecated, please upgrade your PHP version.\e[0m\n";
}

try {
    (new ConsoleApplication())->run();
} catch (SPCException $e) {
    exit(ExceptionHandler::handleSPCException($e));
} catch (\Throwable $e) {
    exit(ExceptionHandler::handleDefaultException($e));
}

