From 96db459246ee79295a7f70cca838b0dbf11f5a55 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 11 Mar 2022 13:47:53 +0000 Subject: [PATCH 1/2] Add --name option to schedule:test command. --- .../Console/Scheduling/ScheduleTestCommand.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php index f9bee078d58a..ac55b5744fb0 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,17 @@ 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($name = $this->option('name'))) { + $matches = array_filter($commandNames, fn ($commandName) => Str::endsWith($commandName, $name)); + + if (count($matches) !== 1) { + return $this->error('No scheduled command found'); + } + + $index = key($matches); + } else { + $index = array_search($this->choice('Which command would you like to run?', $commandNames), $commandNames); + } $event = $commands[$index]; From 671472b23be085f938fbdc6e931ce9c8ad39fb93 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 11 Mar 2022 08:23:24 -0600 Subject: [PATCH 2/2] formatting --- src/Illuminate/Console/Scheduling/ScheduleTestCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php index ac55b5744fb0..0e9001449e9b 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleTestCommand.php @@ -46,11 +46,15 @@ public function handle(Schedule $schedule) $commandNames[] = $command->command ?? $command->getSummaryForDisplay(); } + 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 scheduled command found'); + return $this->error('No matching scheduled command found.'); } $index = key($matches);