From 1f3f543adf5879b539459e7d52fb1bdd01ca7894 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Mon, 18 Nov 2024 18:00:49 +0100 Subject: [PATCH] added confirmation to purge queue --- src/Command/PurgeQueueCommand.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Command/PurgeQueueCommand.php b/src/Command/PurgeQueueCommand.php index b7bd6c5..907dc68 100644 --- a/src/Command/PurgeQueueCommand.php +++ b/src/Command/PurgeQueueCommand.php @@ -65,6 +65,12 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar ->setDescription(self::getDescription()) ->addArgument('queue-config', [ 'help' => __('Queue configuration key'), + ]) + ->addOption('yes', [ + 'short' => 'y', + 'boolean' => true, + 'default' => false, + 'help' => __('Yes - skip confirmation prompt') ]); } @@ -91,10 +97,25 @@ public function execute(Arguments $args, ConsoleIo $io) } else { $io->error(__('There are no queue configurations')); } + $this->displayHelp($this->getOptionParser(), $args, $io); return self::CODE_ERROR; } + if (!$args->getOption('yes')) { + $confirmation = $io->askChoice( + __('Are you sure you want to purge messages from specified queue?'), + [ + __('yes'), + __('no') + ], + __('no') + ); + + if ($confirmation === __('no')) { + $io->abort(__('Aborting')); + } + } try { $this->enqueueClientService->purgeQueue($queueConfig); $io->success(__('Queue purged successfully'));