From 6df27293175dc0a7c8911fd68f6e4984689749c7 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 1 May 2022 16:46:01 +0300 Subject: [PATCH] feat(console): improve `entries:delete` logic --- .../Commands/Entries/EntriesDeleteCommand.php | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php index 9f27037e..ba1a52f2 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php @@ -20,7 +20,8 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; +use function Thermage\div; +use function Thermage\renderToString; class EntriesDeleteCommand extends Command { @@ -33,13 +34,33 @@ class EntriesDeleteCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); + $id = $input->getArgument('id'); - if (entries()->delete($input->getArgument('id'))) { - $io->success('Entry ' . $input->getArgument('id') . ' deleted.'); + if (! entries()->has($id)) { + $output->write( + renderToString( + div('Failure: Entry [b]' . $id . '[/b] doesn\'t exists.', + 'bg-danger px-2 py-1') + ) + ); + return Command::FAILURE; + } + + if (entries()->delete($id)) { + $output->write( + renderToString( + div('Success: Entry [b]' . $id . '[/b] deleted.', + 'bg-success px-2 py-1') + ) + ); return Command::SUCCESS; } else { - $io->error('Entry ' . $input->getArgument('id') . ' wasn\'t deleted.'); + $output->write( + renderToString( + div('Failure: Entry [b]' . $id . '[/b] wasn\'t deleted.', + 'bg-danger px-2 py-1') + ) + ); return Command::FAILURE; } }