Files
backupscript/src/CommandShow.php
Jens True 6ce774236e
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Build and test / requirements (push) Failing after 3m48s
Quality of life things.
2024-02-07 11:00:08 +00:00

58 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'show',
description: 'Show all backup entries.',
)]
class CommandShow extends Command
{
protected function configure(): void
{
$this->addArgument(
'config',
InputArgument::REQUIRED,
'Configuration file'
);
}
/**
* 1. Read the configuration file.
* 2. For each configured backup print the details
* 3. Exit
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$sio = new SymfonyStyle($input, $output);
$sio->title('List backup entities');
try {
$app = new App((string)$input->getArgument('config'));
} catch (\Throwable $e) {
$sio->error('Configuration error: ' . $e->getMessage());
return Command::FAILURE;
}
/**
* @var array{title: string, source: string, destination: string}[]
*/
$backupElements = $app->getConfig('backup');
$sio->table(
['Description', 'Source', 'Destination'],
$backupElements
);
$sio->success("Done");
return Command::SUCCESS;
}
}