backupscript/src/CommandShow.php
2023-05-31 09:00:20 +00:00

41 lines
1.3 KiB
PHP

<?php
namespace App;
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;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;
class CommandShow extends Command
{
static $defaultName = "show";
static $defaultDescription = "Show all backup entries";
protected function configure(): void
{
$this->addArgument('config', InputArgument::OPTIONAL, 'Configuration file', "config.yml");
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('List backup entities');
$io->note('Reading from: '.$input->getArgument('config'));
try {
$config = Yaml::parseFile($input->getArgument('config'));
} catch (ParseException $e) {
$io->error('Unable to parse the YAML string: '. $e->getMessage());
return Command::FAILURE;
}
$io->table(['Description', 'Source', 'Destination'], $config['backup']);
$io->success("Done");
return Command::SUCCESS;
}
}