File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
src/Illuminate/Console/Scheduling Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 3
3
namespace Illuminate \Console \Scheduling ;
4
4
5
5
use Illuminate \Console \Command ;
6
+ use Illuminate \Support \Str ;
6
7
7
8
class ScheduleTestCommand extends Command
8
9
{
@@ -11,7 +12,7 @@ class ScheduleTestCommand extends Command
11
12
*
12
13
* @var string
13
14
*/
14
- protected $ name = 'schedule:test ' ;
15
+ protected $ signature = 'schedule:test {--name= : The name of the scheduled command to run} ' ;
15
16
16
17
/**
17
18
* The name of the console command.
@@ -45,7 +46,21 @@ public function handle(Schedule $schedule)
45
46
$ commandNames [] = $ command ->command ?? $ command ->getSummaryForDisplay ();
46
47
}
47
48
48
- $ index = array_search ($ this ->choice ('Which command would you like to run? ' , $ commandNames ), $ commandNames );
49
+ if (empty ($ commandNames )) {
50
+ return $ this ->comment ('No scheduled commands have been defined. ' );
51
+ }
52
+
53
+ if (! empty ($ name = $ this ->option ('name ' ))) {
54
+ $ matches = array_filter ($ commandNames , fn ($ commandName ) => Str::endsWith ($ commandName , $ name ));
55
+
56
+ if (count ($ matches ) !== 1 ) {
57
+ return $ this ->error ('No matching scheduled command found. ' );
58
+ }
59
+
60
+ $ index = key ($ matches );
61
+ } else {
62
+ $ index = array_search ($ this ->choice ('Which command would you like to run? ' , $ commandNames ), $ commandNames );
63
+ }
49
64
50
65
$ event = $ commands [$ index ];
51
66
You can’t perform that action at this time.
0 commit comments