Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add --name option to schedule:test command #41439

Merged
merged 2 commits into from Mar 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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