#!/usr/bin/env php
<?php
/**
 * File Cache Cleaner 
 *  - Command line loader
 *  - https://github.com/attogram/file-cache-cleaner
 */
declare(strict_types = 1);

use Attogram\Cache\FileCacheCleaner;

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

$autoloaded = false;

foreach ($autoloadLocations as $load) {
    if (is_readable($load)) {
        $autoloaded = true;
        require_once($load);
        break;
    }
}

if (!$autoloaded) {
    exit('autoload.php not found.');
}

if (!isset($argv[0])) {
    exit('Command Line Usage only.');
}

try {
    (new FileCacheCleaner())->clean($argv);
} catch (Throwable $error) {
    print "\nError: " . get_class($error) . ': ' . $error->getMessage();
}
