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

if (!defined('HIPPO_COMPOSER_INSTALL')) {
	die(
		'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
	);
}

require HIPPO_COMPOSER_INSTALL;

use \HippoPHP\Hippo\HippoTextUI;
use \HippoPHP\Hippo\Exception\FileNotFoundException;
use \HippoPHP\Hippo\Exception\UnrecognizedOptionException;
use \HippoPHP\Hippo\Exception\ShutdownException;

function handleGenericError(\Exception $e) {
	echo $e->getMessage() . PHP_EOL;
	exit(1);
}

try {
	HippoTextUI::main(isset($_SERVER['argv']) ? $_SERVER['argv'] : FALSE);
} catch (FileNotFoundException $e) {
	handleGenericError($e);
} catch (UnrecognizedOptionException $e) {
	handleGenericError($e);
} catch (ShutdownException $e) {
	exit($e->getExitCode());
}
