feat: streamline cli command output styles

This commit is contained in:
Björn Fromme
2025-04-25 08:16:07 +02:00
parent d9ab2a6e1f
commit 8d1edc3da0
2 changed files with 10 additions and 2 deletions
+6 -2
View File
@@ -10,6 +10,7 @@ use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand( #[AsCommand(
name: 'app:cleanup:xml-dumps', name: 'app:cleanup:xml-dumps',
@@ -26,6 +27,8 @@ class CleanupXMLDumpsCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$io = new SymfonyStyle($input, $output);
// we look for files older than 1 week // we look for files older than 1 week
$maxDate = (new \DateTimeImmutable())->modify('-1 week')->getTimestamp(); $maxDate = (new \DateTimeImmutable())->modify('-1 week')->getTimestamp();
@@ -37,7 +40,7 @@ class CleanupXMLDumpsCommand extends Command
->map(fn (StorageAttributes $attributes) => $attributes->path()) ->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray(); ->toArray();
} catch (FilesystemException $e) { } catch (FilesystemException $e) {
$output->writeln('<error>'.$e->getMessage().'</error>'); $io->error($e->getMessage());
return Command::FAILURE; return Command::FAILURE;
} }
@@ -47,8 +50,9 @@ class CleanupXMLDumpsCommand extends Command
} }
$message = 'Removed '.count($files).' outdated XML dumps'; $message = 'Removed '.count($files).' outdated XML dumps';
$this->logger->info($message); $this->logger->info($message);
$output->writeln('<info>'.$message.'</info>'); $io->success($message);
return Command::SUCCESS; return Command::SUCCESS;
} }
+4
View File
@@ -7,6 +7,7 @@ use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(name: 'app:crypto:generate-keys', description: 'Generate keypair for encryption')] #[AsCommand(name: 'app:crypto:generate-keys', description: 'Generate keypair for encryption')]
class GenerateKeysCommand extends Command class GenerateKeysCommand extends Command
@@ -20,6 +21,9 @@ class GenerateKeysCommand extends Command
{ {
(new KeyPair())->generate($this->path.'/private.key', $this->path.'/public.key'); (new KeyPair())->generate($this->path.'/private.key', $this->path.'/public.key');
$io = new SymfonyStyle($input, $output);
$io->success('Generated keypair in '.$this->path);
return Command::SUCCESS; return Command::SUCCESS;
} }
} }