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

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

foreach ($autoloaders as $file) {
    if (file_exists($file)) {
        define('PERIDOT_COMPOSER_INSTALL', $file);
        break;
    }
}

unset($autoloaders, $file);

if (!defined('PERIDOT_COMPOSER_INSTALL')) {
    fwrite(STDERR,
        'You need to set up the project dependencies using the following commands:' . PHP_EOL .
        'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
        'php composer.phar install' . PHP_EOL
    );
    exit(1);
}

require_once PERIDOT_COMPOSER_INSTALL;

use Evenement\EventEmitter;
use Peridot\Console\Application;
use Peridot\Console\CliOptionParser;
use Peridot\Console\Environment;
use Peridot\Console\InputDefinition;

$parser = new CliOptionParser(['-c', '--configuration'], $argv);
$environment = new Environment(
    new InputDefinition(),
    new EventEmitter(),
    $parser->parse()
);

$application = new Application($environment);
$application->run();
