From beb047f2c38c008efa5d47de929893a63718014a Mon Sep 17 00:00:00 2001 From: Alpha Date: Thu, 25 Apr 2024 17:16:36 -0400 Subject: [PATCH] fix: unable to remove lazy loaded commands --- src/Kernel.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Kernel.php b/src/Kernel.php index 258b71e8..aa759c0e 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -205,9 +205,18 @@ function ($artisan) use ($toRemoveCommands) { * command class. */ Artisan::starting( - function ($artisan) use ($commands) { + function ($artisan) use ($commands, $toRemoveCommands) { $artisan->resolveCommands($commands->toArray()); + $reflectionClass = new ReflectionClass(Artisan::class); + $property = $reflectionClass->getProperty('commandMap'); + $commandMap = collect($property->getValue($artisan)) + ->filter( + fn ($command) => ! in_array($command, $toRemoveCommands, true) + ) + ->toArray(); + $property->setValue($artisan, $commandMap); + $artisan->setContainerCommandLoader(); } );