From 8b0af92eb46f4c64d5dd2ac24c632c592aab7c3b Mon Sep 17 00:00:00 2001 From: Jamie York Date: Fri, 11 Mar 2022 14:23:52 +0000 Subject: [PATCH] [9.x] Add --name option to schedule:test command (#41439) * Add --name option to schedule:test command. * formatting Co-authored-by: Taylor Otwell --- .../Scheduling/ScheduleTestCommand.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php index f9bee078d58a..0e9001449e9b 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Console\Scheduling; use Illuminate\Console\Command; +use Illuminate\Support\Str; class ScheduleTestCommand extends Command { @@ -11,7 +12,7 @@ class ScheduleTestCommand extends Command * * @var string */ - protected $name = 'schedule:test'; + protected $signature = 'schedule:test {--name= : The name of the scheduled command to run}'; /** * The name of the console command. @@ -45,7 +46,21 @@ public function handle(Schedule $schedule) $commandNames[] = $command->command ?? $command->getSummaryForDisplay(); } - $index = array_search($this->choice('Which command would you like to run?', $commandNames), $commandNames); + if (empty($commandNames)) { + return $this->comment('No scheduled commands have been defined.'); + } + + if (! empty($name = $this->option('name'))) { + $matches = array_filter($commandNames, fn ($commandName) => Str::endsWith($commandName, $name)); + + if (count($matches) !== 1) { + return $this->error('No matching scheduled command found.'); + } + + $index = key($matches); + } else { + $index = array_search($this->choice('Which command would you like to run?', $commandNames), $commandNames); + } $event = $commands[$index];