diff --git a/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php b/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php index 40104973..ef1b6da0 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php @@ -37,20 +37,18 @@ class CacheDeleteCommand extends Command $key = $input->getArgument('key'); if (cache()->delete($key)) { - $io->success('Cache item with key ' . $key . ' deleted.'); $output->write( renderToString( - div('Success: Cache item with key ' . $key . ' created.', + div('Success: Cache item with key ' . $key . ' deleted.', 'bg-success px-2 py-1') ) ); return Command::SUCCESS; } else { - $io->error('Cache item with key ' . $key . ' wasn\'t deleted.'); $output->write( renderToString( - div('Success: Cache item with key ' . $key . ' created.', - 'bg-success px-2 py-1') + div('Failure: Cache item with key ' . $key . ' wasn\'t deleted.', + 'bg-danger px-2 py-1') ) ); return Command::FAILURE; diff --git a/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php index 0aff7eb0..a070557e 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php @@ -20,7 +20,8 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Style\SymfonyStyle; +use function Thermage\div; +use function Thermage\renderToString; class CacheDeleteMultipleCommand extends Command { @@ -33,15 +34,27 @@ class CacheDeleteMultipleCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - $io = new SymfonyStyle($input, $output); - - $keys = $input->getArgument('keys') ? serializers()->json()->decode($input->getArgument('keys')) : []; + if ($input->getArgument('keys')) { + $keys = collectionFromString($input->getArgument('keys'), ',')->map(fn($key) => trim($key))->toArray(); + } else { + $keys = []; + } if (cache()->deleteMultiple($keys)) { - $io->success('Cache items with keys ' . implode(', ', $keys) . ' deleted.'); + $output->write( + renderToString( + div('Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] deleted.', + 'bg-success px-2 py-1') + ) + ); return Command::SUCCESS; } else { - $io->error('Cache items with keys ' . implode(', ', $keys) . ' wasn\'t deleted.'); + $output->write( + renderToString( + div('Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] wasn\'t deleted.', + 'bg-danger px-2 py-1') + ) + ); return Command::FAILURE; } } diff --git a/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php b/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php index 3e437d74..a1257256 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php @@ -19,8 +19,9 @@ namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Input\InputArgument; +use function Thermage\div; +use function Thermage\renderToString; class CacheGetCommand extends Command { @@ -37,7 +38,11 @@ class CacheGetCommand extends Command $key = $input->getArgument('key'); $default = $input->getArgument('default') ?? null; - $output->writeln(cache()->get($key, $default)); + $output->write( + renderToString( + div('[b][color=success]Key:[/color][/b] ' . $key . "\n" . '[b][color=success]Value:[/color][/b] ' . cache()->get($key, $default), 'px-2 border-square border-color-success') + ) + ); return Command::SUCCESS; } diff --git a/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php index 6362b2a1..98b3b466 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php @@ -32,7 +32,6 @@ class CacheGetMultipleCommand extends Command $this->setDescription('Get multiple items.'); $this->addArgument('keys', InputArgument::REQUIRED, 'Keys.'); $this->addArgument('default', InputArgument::OPTIONAL, 'Default.'); - $this->addOption('output', null, InputOption::VALUE_REQUIRED, 'Set this flag to set result output style: pretty(default), json.'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -42,35 +41,14 @@ class CacheGetMultipleCommand extends Command $data = cache()->getMultiple($keys, $default); - $prettyPrint = function ($data) use ($output) { - foreach ($data as $key => $value) { - $output->write( - renderToString( - div('[b]Key:[/b] ' . $key . "\n" . '[b]Value:[/b] ' . $value, 'px-2 border-square') - ) - ); - } - }; - - if ($input->getOption('output')) { - switch ($input->getOption('output')) { - case 'json': - $output->write( - renderToString( - div(json_encode($data)) - ) - ); - break; - - case 'pretty': - default: - $prettyPrint($data); - break; - } - } else { - $prettyPrint($data); + foreach ($data as $key => $value) { + $output->write( + renderToString( + div('[b][color=success]Key:[/color][/b] ' . $key . "\n" . '[b][color=success]Value:[/color][/b] ' . $value, 'px-2 border-square border-color-success') + ) + ); } - + return Command::SUCCESS; } } \ No newline at end of file diff --git a/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php index 63c7bb09..b7443b58 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php @@ -20,7 +20,6 @@ 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;