refactor(cli): migrate 64 legacy scripts to CliFramework (#235)
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Generic: Repo Health / Release configuration (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled

Wrap all CLI tools in cli/, automation/, maintenance/, deploy/, and
release/ in classes extending CliFramework. Replaces manual $argv
parsing with configure()/addArgument(), moves logic into run(): int,
and converts fwrite(STDERR,...) to $this->log(). Two CLIApp subclasses
(generate_dolibarr_version_txt, generate_joomla_update_xml) converted
to extend CliFramework directly.

Every script now gets free --help, --verbose, --quiet, --dry-run,
--json, --no-color, banners, coloured logging, and progress bars.

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-05-31 11:39:10 -05:00
parent af77e9d361
commit b3d9ee8255
64 changed files with 9792 additions and 11200 deletions
+53 -93
View File
@@ -9,13 +9,17 @@
* INGROUP: moko-platform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
* PATH: /cli/wiki_sync.php
* VERSION: 09.21.00
* VERSION: 09.21.07
* BRIEF: Sync select wiki pages from moko-platform to all template repos
*/
declare(strict_types=1);
final class WikiSync
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
use MokoEnterprise\CliFramework;
class WikiSyncCli extends CliFramework
{
private string $giteaUrl = 'https://git.mokoconsulting.tech';
private string $token = '';
@@ -23,27 +27,52 @@ final class WikiSync
private string $sourceRepo = 'moko-platform';
private array $targetRepos = [];
private array $pages = [];
private bool $dryRun = false;
private bool $allTemplates = false;
private bool $allStandards = false;
private int $synced = 0;
private int $created = 0;
private int $skipped = 0;
private int $errors = 0;
public function run(): int
protected function configure(): void
{
$this->parseArgs();
$this->setDescription('Sync wiki pages from moko-platform to template repos');
$this->addArgument('--token', 'Gitea API token (required)', '');
$this->addArgument('--org', 'Organization (default: MokoConsulting)', 'MokoConsulting');
$this->addArgument('--source', 'Source repo (default: moko-platform)', 'moko-platform');
$this->addArgument('--target', 'Target repo (can repeat)', '');
$this->addArgument('--page', 'Page to sync (can repeat)', '');
$this->addArgument('--all-standards', 'Sync all UPPERCASE standards pages', false);
$this->addArgument('--all-templates', 'Target all Template-* repos', false);
}
protected function run(): int
{
$this->token = $this->getArgument('--token');
$this->org = $this->getArgument('--org');
$this->sourceRepo = $this->getArgument('--source');
$this->allStandards = (bool) $this->getArgument('--all-standards');
$this->allTemplates = (bool) $this->getArgument('--all-templates');
// Handle repeatable args from raw argv
global $argv;
foreach ($argv as $i => $arg) {
if ($arg === '--target' && isset($argv[$i + 1])) {
$this->targetRepos[] = $argv[$i + 1];
}
if ($arg === '--page' && isset($argv[$i + 1])) {
$this->pages[] = $argv[$i + 1];
}
}
if ($this->token === '') {
$this->log('ERROR: --token is required.');
$this->printUsage();
$this->log('ERROR', '--token is required.');
return 1;
}
if (empty($this->pages) && !$this->allTemplates) {
$this->log('ERROR: --page or --all-standards is required.');
$this->printUsage();
if (empty($this->pages) && !$this->allStandards) {
$this->log('ERROR', '--page or --all-standards is required.');
return 1;
}
@@ -53,7 +82,7 @@ final class WikiSync
}
if (empty($this->targetRepos)) {
$this->log('No target repos found.');
$this->log('INFO', 'No target repos found.');
return 0;
}
@@ -62,16 +91,16 @@ final class WikiSync
$this->pages = $this->getStandardsPages();
}
$this->log("Syncing " . count($this->pages) . " page(s) to " . count($this->targetRepos) . " repo(s)");
$this->log('INFO', "Syncing " . count($this->pages) . " page(s) to " . count($this->targetRepos) . " repo(s)");
if ($this->dryRun) {
$this->log("[DRY RUN] No changes will be made.\n");
$this->log('INFO', "[DRY RUN] No changes will be made.\n");
}
foreach ($this->pages as $pageName) {
$this->log("\n--- Page: {$pageName} ---");
$this->log('INFO', "\n--- Page: {$pageName} ---");
$sourceContent = $this->getWikiPage($this->sourceRepo, $pageName);
if ($sourceContent === null) {
$this->log(" WARNING: page not found in {$this->sourceRepo}");
$this->log('WARNING', "page not found in {$this->sourceRepo}");
$this->errors++;
continue;
}
@@ -79,30 +108,30 @@ final class WikiSync
foreach ($this->targetRepos as $repo) {
$existing = $this->getWikiPage($repo, $pageName);
if ($existing !== null && $existing === $sourceContent) {
$this->log(" {$repo}: IDENTICAL (skipped)");
$this->log('INFO', " {$repo}: IDENTICAL (skipped)");
$this->skipped++;
continue;
}
if ($this->dryRun) {
$action = $existing !== null ? 'WOULD UPDATE' : 'WOULD CREATE';
$this->log(" {$repo}: {$action}");
$this->log('INFO', " {$repo}: {$action}");
continue;
}
if ($existing !== null) {
$ok = $this->updateWikiPage($repo, $pageName, $sourceContent);
$this->log(" {$repo}: " . ($ok ? 'UPDATED' : 'ERROR'));
$this->log('INFO', " {$repo}: " . ($ok ? 'UPDATED' : 'ERROR'));
$ok ? $this->synced++ : $this->errors++;
} else {
$ok = $this->createWikiPage($repo, $pageName, $sourceContent);
$this->log(" {$repo}: " . ($ok ? 'CREATED' : 'ERROR'));
$this->log('INFO', " {$repo}: " . ($ok ? 'CREATED' : 'ERROR'));
$ok ? $this->created++ : $this->errors++;
}
}
}
$this->log("\nDone: {$this->synced} updated, {$this->created} created, {$this->skipped} skipped, {$this->errors} error(s)");
$this->log('INFO', "\nDone: {$this->synced} updated, {$this->created} created, {$this->skipped} skipped, {$this->errors} error(s)");
return $this->errors > 0 ? 1 : 0;
}
@@ -116,7 +145,7 @@ final class WikiSync
}
}
sort($templates);
$this->log("Found template repos: " . implode(', ', $templates));
$this->log('INFO', "Found template repos: " . implode(', ', $templates));
return $templates;
}
@@ -132,7 +161,7 @@ final class WikiSync
}
}
sort($standards);
$this->log("Found " . count($standards) . " standards pages: " . implode(', ', $standards));
$this->log('INFO', "Found " . count($standards) . " standards pages: " . implode(', ', $standards));
return $standards;
}
@@ -207,76 +236,7 @@ final class WikiSync
$data = json_decode($result, true);
return is_array($data) ? $data : null;
}
private function parseArgs(): void
{
global $argv;
$args = $argv;
for ($i = 1; $i < count($args); $i++) {
switch ($args[$i]) {
case '--token':
$this->token = $args[++$i] ?? '';
break;
case '--org':
$this->org = $args[++$i] ?? '';
break;
case '--source':
$this->sourceRepo = $args[++$i] ?? '';
break;
case '--target':
$this->targetRepos[] = $args[++$i] ?? '';
break;
case '--page':
$this->pages[] = $args[++$i] ?? '';
break;
case '--all-standards':
$this->pages = []; // will be populated from source wiki
$this->allTemplates = true;
break;
case '--all-templates':
$this->allTemplates = true;
break;
case '--dry-run':
$this->dryRun = true;
break;
case '--help':
case '-h':
$this->printUsage();
exit(0);
default:
$this->log("WARNING: Unknown argument: {$args[$i]}");
break;
}
}
}
private function printUsage(): void
{
$this->log('Usage: wiki_sync.php --token <token> [options]');
$this->log('');
$this->log('Sync wiki pages from moko-platform to template repos.');
$this->log('');
$this->log('Options:');
$this->log(' --token <token> Gitea API token (required)');
$this->log(' --org <org> Organization (default: MokoConsulting)');
$this->log(' --source <repo> Source repo (default: moko-platform)');
$this->log(' --target <repo> Target repo (can repeat; default: all Template-* repos)');
$this->log(' --page <name> Page to sync (can repeat)');
$this->log(' --all-standards Sync all UPPERCASE standards pages');
$this->log(' --all-templates Target all Template-* repos');
$this->log(' --dry-run Show what would be done');
$this->log(' --help, -h Show this help');
$this->log('');
$this->log('Examples:');
$this->log(' php wiki_sync.php --token xxx --page MANIFEST_STANDARD --all-templates');
$this->log(' php wiki_sync.php --token xxx --all-standards --all-templates --dry-run');
$this->log(' php wiki_sync.php --token xxx --page WORKFLOW_STANDARDS --target Template-Joomla');
}
private function log(string $msg): void
{
fwrite(STDERR, $msg . "\n");
}
}
(new WikiSync())->run();
$app = new WikiSyncCli();
exit($app->execute());