<?php
/**
 * Wrapper CLI pour PSLauncher\Tools\SignManifest.
 *
 * Usage :
 *   cd ~/www/PS_Launcher && php tools/sign-manifest.php
 *   php tools/sign-manifest.php --scope=launcher       # ne re-signe que la section launcher
 *   php tools/sign-manifest.php --scope=versions       # ne re-signe que les builds Proserve
 *   php tools/sign-manifest.php --force                # ignore le cache, recalcule tous les SHA-256
 *
 * Le backoffice admin appelle directement la classe (pas d'exec).
 */
declare(strict_types=1);

require __DIR__ . '/SignManifest.php';

$scope = 'all';
$force = false;
foreach (array_slice($argv, 1) as $arg) {
    if ($arg === '--force' || $arg === '-f') $force = true;
    elseif (str_starts_with($arg, '--scope=')) $scope = substr($arg, 8);
    elseif (in_array($arg, ['versions', 'launcher', 'all'], true)) $scope = $arg;
}

$signer = new \PSLauncher\Tools\SignManifest(dirname(__DIR__));
$result = $signer->run($scope, $force);
foreach ($result['log'] as $line) echo $line . "\n";
exit($result['ok'] ? 0 : 1);
