From 8d1edc3da0cf1868f7b25f755e5f5271957e99f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 25 Apr 2025 08:16:07 +0200 Subject: [PATCH] feat: streamline cli command output styles --- src/Command/CleanupXMLDumpsCommand.php | 8 ++++++-- src/Command/GenerateKeysCommand.php | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Command/CleanupXMLDumpsCommand.php b/src/Command/CleanupXMLDumpsCommand.php index e083d92..d78655d 100644 --- a/src/Command/CleanupXMLDumpsCommand.php +++ b/src/Command/CleanupXMLDumpsCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; #[AsCommand( name: 'app:cleanup:xml-dumps', @@ -26,6 +27,8 @@ class CleanupXMLDumpsCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { + $io = new SymfonyStyle($input, $output); + // we look for files older than 1 week $maxDate = (new \DateTimeImmutable())->modify('-1 week')->getTimestamp(); @@ -37,7 +40,7 @@ class CleanupXMLDumpsCommand extends Command ->map(fn (StorageAttributes $attributes) => $attributes->path()) ->toArray(); } catch (FilesystemException $e) { - $output->writeln(''.$e->getMessage().''); + $io->error($e->getMessage()); return Command::FAILURE; } @@ -47,8 +50,9 @@ class CleanupXMLDumpsCommand extends Command } $message = 'Removed '.count($files).' outdated XML dumps'; + $this->logger->info($message); - $output->writeln(''.$message.''); + $io->success($message); return Command::SUCCESS; } diff --git a/src/Command/GenerateKeysCommand.php b/src/Command/GenerateKeysCommand.php index 8c85df5..adfebee 100644 --- a/src/Command/GenerateKeysCommand.php +++ b/src/Command/GenerateKeysCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; #[AsCommand(name: 'app:crypto:generate-keys', description: 'Generate keypair for encryption')] class GenerateKeysCommand extends Command @@ -20,6 +21,9 @@ class GenerateKeysCommand extends Command { (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; } }