Skip to content

Commit

Permalink
[9.x] Add --name option to schedule:test command (#41439)
Browse files Browse the repository at this point in the history
* Add --name option to schedule:test command.

* formatting

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
ziadoz and taylorotwell committed Mar 11, 2022
1 parent 9684a04 commit 8b0af92
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Illuminate/Console/Scheduling/ScheduleTestCommand.php
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Console\Scheduling;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class ScheduleTestCommand extends Command
{
Expand All @@ -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.
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 8b0af92

Please sign in to comment.