#!/usr/bin/env php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
    if (file_exists($file)) {
        require $file;
        break;
    }
}

use Symfony\Component\Console\Application;
use Magento\SemanticVersionChecker\Console\Command\CompareSourceCommand;

if (PHP_SAPI !== 'cli') {
    echo 'Command "bin/svc" must be run as a CLI application.' . PHP_EOL;
    exit(1);
}

try {
    $composerContents = json_decode(file_get_contents(__DIR__ . '/../composer.json'), true);
    $application = new Symfony\Component\Console\Application(
            $composerContents['description'],
            $composerContents['version']
    );
    $application->add(new CompareSourceCommand());
    $application->run();
} catch (\Exception $e) {
    while ($e) {
        echo $e->getMessage();
        echo $e->getTraceAsString();
        echo "\n\n";
        $e = $e->getPrevious();
    }
    exit(1);
}
