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


use Composer\InstalledVersions;
use Symfony\Component\Console\Application;
use TgScraper\Commands\CreateStubsCommand;
use TgScraper\Commands\DumpSchemasCommand;
use TgScraper\Commands\ExportSchemaCommand;

$autoloadFiles = [
    __DIR__ . '/../vendor/autoload.php',
    __DIR__ . '/../../../autoload.php'
];

foreach ($autoloadFiles as $autoloadFile) {
    if (file_exists($autoloadFile)) {
        require_once $autoloadFile;
        break;
    }
}

$application = new Application('TGScraper', InstalledVersions::getVersion('sysbot/tgscraper'));

$application->add(new CreateStubsCommand());
$application->add(new ExportSchemaCommand());
$application->add(new DumpSchemasCommand());

try {
    $exitCode = $application->run();
} catch (Throwable $e) {
    echo $e->getMessage() . PHP_EOL;
}

exit($exitCode ?? 1);
