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

(@include_once __DIR__ . '/../vendor/autoload.php') || @include_once __DIR__ . '/../../../autoload.php';

use CacheTool\Console\Application;
use CacheTool\Console\Config;
use Symfony\Component\Yaml\Yaml;

function loadConfig() {
    $previous = null;
    $path = getcwd();
    $paths = array();

    while (($path = realpath($path)) && $path !== $previous) {
        $paths[] = "{$path}/.cachetool.yml";
        $previous = $path;
        $path .= '/../';
    }

    $paths[] = '/etc/cachetool.yml';

    foreach ($paths as $path) {
        if (is_file($path)) {
            return new Config(Yaml::parse($path));
        }
    }

    return new Config();
}

$config = loadConfig();
$application = new Application($config);
$application->run();
