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

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

$autoloaded = false;

foreach ($autoloadPaths as $autoloadPath) {
    if (file_exists($autoloadPath)) {
        require $autoloadPath;
        $autoloaded = true;

        break;
    }
}

if (! $autoloaded) {
    fwrite(STDERR, "Could not find Composer autoloader. Run 'composer install' first.\n");
    exit(1);
}

use RalphJSmit\Guidelines\GuidelineCompiler;
use RalphJSmit\Guidelines\GuidelinesInstaller;

$command = $argv[1] ?? 'install';

$onStatus = function (string $path, string $status): void {
    echo "  {$path}: {$status}\n";
};

match ($command) {
    'install' => (new GuidelinesInstaller(getcwd(), $onStatus))->install(),
    'compile-boost' => (new GuidelineCompiler)->compileBoost($onStatus),
    default => fwrite(STDERR, "Unknown command: {$command}\nUsage: guidelines [install|compile-boost]\n") || exit(1),
};
