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

if (!ini_get('date.timezone')) {
    ini_set('date.timezone', 'UTC');
}

foreach(['vendor',null] as $vendor_dir)
{

    if(defined('PHPUNIT_COMPOSER_INSTALL'))
    {
        continue;
    }

    $dir = [__DIR__];
    for($a=0;$a<=3;$a++)
    {
        $dir[]= '..';
        $file = implode(DIRECTORY_SEPARATOR, $dir);
        if($vendor_dir)
        {
            $file.= DIRECTORY_SEPARATOR . 'vendor';
        }

        $file.= DIRECTORY_SEPARATOR . 'autoload.php';

        echo $file .PHP_EOL;

        if (file_exists($file)) {
            define('PHPUNIT_COMPOSER_INSTALL', $file);
            break;
        }
    }
}

unset($file);

if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
    fwrite(STDERR,
        'You need to set up the project dependencies using the following commands:' . PHP_EOL .
        'wget http://getcomposer.org/composer.phar' . PHP_EOL .
        'php composer.phar install' . PHP_EOL
    );
    die(1);
}

require PHPUNIT_COMPOSER_INSTALL;


use Symfony\Component\Console\Application;

$application = new Application();
$application->add(new JuliusHaertl\PHPDocToRst\GenerateDocumentationCommand());
$application->run();
