From d87d0b79920cc6da658c19e4cb3c1afe75e3e9d9 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 1 May 2022 16:10:23 +0300 Subject: [PATCH] feat(console): improve `entries:copy` logic --- .../Commands/Entries/EntriesCopyCommand.php | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php index ec36753f..79ac0e76 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php @@ -21,6 +21,8 @@ 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 EntriesCopyCommand extends Command { @@ -34,13 +36,34 @@ class EntriesCopyCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); + $id = $input->getArgument('id'); + $newID = $input->getArgument('newID'); - if (entries()->copy($input->getArgument('id'), $input->getArgument('newID'))) { - $io->success('Entry ' . $input->getArgument('id') . ' coppied to ' . $input->getArgument('newID')); + 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()->copy($id, $newID)) { + $output->write( + renderToString( + div('Success: Entry [b]' . $id . '[/b] coppied to [b]' . $newID . '[/b]', + 'bg-success px-2 py-1') + ) + ); return Command::SUCCESS; } else { - $io->error('Entry ' . $input->getArgument('id') . ' wasn\'t coppied to ' . $input->getArgument('newID')); + $output->write( + renderToString( + div('Failure: Entry [b]' . $id . '[/b] wasn\'t coppied to [b]' . $newID . '[/b]', + 'bg-success px-2 py-1') + ) + ); return Command::FAILURE; } }