Does anyone know how to programmatically list all custom Artisan commands of a Laravel application?
I know one can do this \Artisan::all() or this app(Kernel::class)->all(). And the list can be found in the $commands property of \App\Console\Kernel, but that property is protected and I would like to have it outside that class.
I could probably use Reflection, but I'm hoping there is another way?
Hi, thanks @tray2, I'm not sure why it would be more dangerous than doing \Artisan::all()?
To put it differently, I would like to have a way to have the same result as \Artisan::all() but without the default Artisan commands. That is, without migrate, migrate:*, key:generate and all the other ones which come with a default Laravel installation.
In fact, even the command signatures would be enough (the keys from \Artisan::all()).
Hi @ajpw, yes, I was looking for something more future-proof - not having to update the filtering whenever Laravel adds or removes a default command. (It is for a composer package.)
Ok, I found a solution - as often, hidden in plain sight. \Artisan::all() returns the instantiated commands as values, so I can verify if they are in the App\Console\Commands namespace!