'Remove commands from php artisan list

Is there a way to remove some commands from the php artisan list?

I find that it is too long and often I have to scroll or do grepping. For example, some project I don't use queue and hiding the queue commands will be useful.



Solution 1:[1]

There's no good way to do that. Most of the core artisan commands list is stored in the Illuminate\Foundation\Providers\ArtisanServiceProvider class within the $commands property. Some are registered directly from their respective service providers, like the Queue ones in Illuminate\Queue\QueueServiceProvider. So in theory you could comment them out there, but you should't be making any changes in the vendor directory in the first place, because they can be undone on any update.

If you find yourself having to check the command list too often, you would be better off taking a little time to commit to memory at least the commands you use on a regular basis, because it would make your workflow far more efficient.


If by any chance you're using zsh with Oh My Zsh, then you could use the included laravel5 plugin which offers autocomplete in your terminal, for all registered Laravel commands. Just write php artisan and press TAB for an autocomplete list of the commands, no scrolling required :).

Solution 2:[2]

As updated by Bogdan, there is no good way to remove command from artisan list. One option available is to override the existing command with new command with same $signature.

Solution 3:[3]

If all the commands you are interested in start with the same prefix, for example prefix:, you can list them using artisan list prefix.

Solution 4:[4]

The accepted answer (Steven's) is a good and clean way to remove the dev commands from the list, which certainly helps a lot, but doesn't clear everything. For example, you are still left with 'inspiration', 'make:migration', etc commands and any additional packages that you might have installed, would have probably added one or two more items in the list.

If your case is like mine and you would simply like to hide the commands from the list (but not disable them entirely), then there is an extremely simple solution:

Create a new command with a 'list' signature. E.g:

/**
  * The name and signature of the console command.
  *
  * @var string
  */
protected $signature = 'list';

Since it will be the last one registered, it will be executed when the framework calls the 'list' command. Inside the command handle, you can use:

$this->getApplication()->all()

to get the list of the registered commands. It will return an array with keys being the command names and the values the actual command objects. You can then use this to decide which to display and which to discard.

Solution 5:[5]

Alight. I finally got a good solution. Create my own bash alias with grep.

Add this to my ~/.bashrc

All my command start with mycompany:command

Use whatever 3 letter shortcut. can for me because it's the first 3 letter of my company's name.

alias can='php artisan | grep mycompany'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jithin Jose
Solution 3 Emil Vikström
Solution 4 Valeri
Solution 5 Yada