#!/usr/bin/env php * * SPDX-License-Identifier: GPL-3.0-or-later * * FILE INFORMATION * DEFGROUP: moko-platform.CLI * INGROUP: moko-platform * REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform * PATH: /cli/badge_update.php * BRIEF: Update [VERSION: XX.XX.XX] badges in all markdown files */ declare(strict_types=1); require_once __DIR__ . '/../lib/Enterprise/CliFramework.php'; use MokoEnterprise\CliFramework; class BadgeUpdateCli extends CliFramework { protected function configure(): void { $this->setDescription('Update VERSION badges in all markdown files'); $this->addArgument('--path', 'Repository root path', '.'); $this->addArgument('--version', 'Version string XX.YY.ZZ', ''); } protected function run(): int { $path = $this->getArgument('--path'); $version = $this->getArgument('--version'); if (empty($version)) { $this->log('ERROR', 'Usage: badge_update.php --path . --version XX.YY.ZZ'); return 1; } $root = realpath($path) ?: $path; $pattern = '/\[VERSION:\s*\d{2}\.\d{2}\.\d{2}\]/'; $replacement = "[VERSION: {$version}]"; $updated = 0; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS) ); foreach ($iterator as $file) { $filePath = $file->getPathname(); if (preg_match('#[/\\\\](\.git|vendor)[/\\\\]#', $filePath)) { continue; } if (!preg_match('/\.md$/i', $filePath)) { continue; } $content = file_get_contents($filePath); if (preg_match($pattern, $content)) { $newContent = preg_replace($pattern, $replacement, $content); if ($newContent !== $content) { if (!$this->dryRun) { file_put_contents($filePath, $newContent); } $relative = str_replace($root . DIRECTORY_SEPARATOR, '', $filePath); $this->log('INFO', "Updated: {$relative}"); $updated++; } } } $this->success("Updated {$updated} file(s) to {$replacement}"); return 0; } } $app = new BadgeUpdateCli(); exit($app->execute());