#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;

/**
 * Include Composer autoload.
 *
 * @return  bool    [return description]
 */
function includeAutoload(): bool
{
    $files = [
        __DIR__ . '/../vendor/autoload.php',
        __DIR__ . '/../../../autoload.php',
        __DIR__ . '/../../../../../vendor/autoload.php'
    ];

    foreach ($files as $file) {
        $included = file_exists($file) && include $file;
        if ($included) {
            return true;
        }
    }

    return false;
}

if (false === includeAutoload()) {
    fwrite(STDERR, 'Install dependencies using Composer.' . PHP_EOL);
    exit(1);
}

try {
    $application = new Application();
    $application->add(new Absszero\Phead\PheadCommand);
    // changfe default command
    $application->setDefaultCommand('phead', true);
    $application->run();
} catch (Throwable $e) {
    echo $e->getFile() . ':' . $e->getLine() . PHP_EOL . PHP_EOL;
    echo $e->getMessage() . PHP_EOL;
    exit(1);
}
