backupscript/src/CommandShow.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2023-05-26 11:47:40 +00:00
<?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\Helper\Table;
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
{
$output->writeln('Reading from: '.$input->getArgument('config'));
try {
$config = Yaml::parseFile($input->getArgument('config'));
2023-05-26 12:14:21 +00:00
} catch (ParseException $e) {
$output->writeln('Unable to parse the YAML string: '. $e->getMessage());
2023-05-26 11:47:40 +00:00
}
$table = new Table($output);
$table
->setHeaders(['Description', 'Source', 'Destination'])
->setRows($config['backup']);
;
$table->render();
return Command::SUCCESS;
}
}