|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +declare(strict_types=1); |
| 5 | + |
| 6 | +require __DIR__.'/../vendor/autoload.php'; |
| 7 | + |
| 8 | +use Symfony\Component\Console\Command\Command; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputInterface; |
| 11 | +use Symfony\Component\Console\Output\OutputInterface; |
| 12 | +use Symfony\Component\Console\SingleCommandApplication; |
| 13 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 14 | +use Terminal42\Restic\Restic; |
| 15 | + |
| 16 | +(new SingleCommandApplication()) |
| 17 | + ->setName('Bump restic version.') |
| 18 | + ->addArgument('version', InputArgument::REQUIRED, 'The desired version.') |
| 19 | + ->setCode( |
| 20 | + static function (InputInterface $input, OutputInterface $output): int { |
| 21 | + $io = new SymfonyStyle($input, $output); |
| 22 | + $version = $input->getArgument('version'); |
| 23 | + |
| 24 | + // Read the file |
| 25 | + $resticClassPath = __DIR__.'/../src/Restic.php'; |
| 26 | + $content = file_get_contents($resticClassPath); |
| 27 | + $pattern = "/public?\\s*const\\s+RESTIC_VERSION\\s*=\\s*'[^']*';/"; |
| 28 | + $replacement = "public const RESTIC_VERSION = '{$version}';"; |
| 29 | + $updatedContent = preg_replace($pattern, $replacement, $content); |
| 30 | + file_put_contents($resticClassPath, $updatedContent); |
| 31 | + |
| 32 | + if (Restic::RESTIC_VERSION !== $version) { |
| 33 | + $io->error('Version could not be updated in Restic class.'); |
| 34 | + |
| 35 | + return Command::FAILURE; |
| 36 | + } |
| 37 | + |
| 38 | + Restic::updateShaSumFile(); |
| 39 | + |
| 40 | + return Command::SUCCESS; |
| 41 | + }, |
| 42 | + ) |
| 43 | + ->run() |
| 44 | +; |
0 commit comments