#!/usr/bin/env php
<?php
foreach ([
__DIR__ . '/../../autoload.php',
 __DIR__ . '/../vendor/autoload.php',
 __DIR__ . '/vendor/autoload.php',
] as $file) {
    if (file_exists($file)) {
        define('BEVERAGE_COMPOSER_INSTALL', $file);
        break;
    }
}

unset($file);

if (!defined('BEVERAGE_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_once BEVERAGE_COMPOSER_INSTALL;
require_once './drinkmenu.php';

use Awakenweb\Beverage\Bootstrapper;
use Awakenweb\Beverage\Command\Run;
use Symfony\Component\Console\Application;

$runner      = new Run();
$application = new Application('Beverage task runner', '0.2');
$application->add($runner);
$application->setDefaultCommand($runner->getName());
$application = Bootstrapper::registerCommands($application, [
        'Awakenweb\Beverage\Command\Init',
        'Awakenweb\Beverage\Command\Watch',
    ]);

if (function_exists('register_custom_commands') && is_array(register_custom_commands())) {
    $application = Bootstrapper::registerCommands($application, register_custom_commands());
}

$application->run();
