In other words: do these 2 command-line tools (still) compliment each other? Can you run them together? And, if not, which one of them should you favor in a Drupal Console vs Drush "debate”?
When would you choose one over the other? And what would you base your choice on? What are their most powerful commands?
Those that would eventually help you choose the best CLI for you?
On one hand, you have good old Drush, with its familiar commands speeding up the most common Drupal development tasks.
And on the other hand, you have Drupal Console and the temptation of a newer CLI tool, along with its main strength: to generate the initial scaffolding for a new project.
Now, let me help you find your answers:
1. Drupal Console vs Drush: What Do They Have in Common?
Before we dig out the differences — or better said “different ways of handling the same tasks“ — let's outline some of the obvious similarities between these tools:
- they're both command-line tools that help you get a new Drupal website up and running in no time and keep interacting with your Drupal installation
- they're both extensible; you get to write your custom commands and to adapt the configuration files to your Drupal project's specific needs
- they both boost your productivity as a Drupal developer by streamlining some otherwise time-consuming Drupal development and management tasks
2. About Drush
An only child in the Drupal ecosystem, Drush used to be the go-to command line for speeding up common tasks like:
- import/export configuration
- installing Drupal
- connecting to the database
- importing mysql
Part of a PHP library, you can install it using Composer.
3. About Drupal Console
The “new(er) kid on the block”, Drupal Console, comes to question the “Drush supremacy” as the go-to CLI for Drupal developers.
And here's what it brings to the table:
- its functionality to generate boilerplate code: it takes no more than a few simple commands to create your custom entity type or custom module
- a low entry point to the otherwise steep Drupal 8 learning curve: it enables you to write more verbose code comments
Based on the Symfony Console library, Drupal Console can get installed, just like Drush, using Composer.
4. Drush: 2 Most Useful Commands
For it's those commands streamlining your tasks that help you pick your final “winner” in a “Drupal Console vs Drush” debate, right?
Now, from all the most useful Drupal development tasks that you can speed up using Drush commands, I've picked but 2. The 2 most critical ones for your Drupal development process and Drupal management tasks:
4.1. Export and Import All Configurations
For import, use this simple Drush command:
While for exporting your config, just enter:
… in your command line.
4.2. Clear (Or Rebuild) Your Cache
You always have Drush as an alternative to the user interface, for clearing or rebuilding your site's internal caches quick and easy:
If you want to first generate a list of all your caches, so you can select the ones to be cleared, just type:
Enter the number associated with the specific cache that you want to clear and press “Enter”.
To clear and rebuild all your cached data use:
5. Drupal Console: 3 Most Powerful Commands
What are the Drupal console commands that Drupal developers are most excited about? Those enabling this CLI to rival good old familiar Drush?
I've carefully picked the 3 most powerful ones for “turbocharging” a developer's workflow:
5.1. The “Generate” Command: Create Your Own Custom Module
Just think about it: a simple command in the root of your Drupal 8 website and you get the whole scaffolding of your future custom module.
And I mean its name, path, dependencies, description... All you need to do is answer the questions that the console's “setup wizard” will prompt you with.
And there's more! More than the boilerplate code that it'll provide you with for your “newly born” custom module.
You can trigger it to help you create:
- a new rule: drupal generate:plugin:rulesaction
- field formatters
- form alters
Furthermore, it's not just modules and their various dependencies that you can generate using this Drupal Console command.
Use generate:theme to create your new theme, feel free to install a profile right from your command-line interface or to use generate:config to set up your configuration, generate:entity:content, generate:bundle...
5.2. The "Debug" Set of Commands
And by far the most commonly used of them is:
… that you get to trigger to debug your routing system.
Yet, this set of commands' debugging functionality covers a lot more aspects of your Drupal website:
- debug: libraries
5.3. Manage Your RESTful Endpoints
Here's another area where Drupal Console turns out to be a powerful competitor for Drush: it enables you to manage your RESTful endpoint plugin configurations right from your CLI.
Just enter this command to get all your currently available RESTful endpoints listed:
$ ./vendor/bin/drupal debug:rest
Then, you can analyze all your plugins individually.
Also, you have another command at your disposal for quickly enabling specific endpoints:
./vendor/bin/drupal rest:enable entity:node
Then, you'll be presented with multiple methods to enable and multiple formats to choose from, as well (e.g. XML or JSON).
6. Why Would You Choose Drupal Console over Drush: Common Reasons
First of all, there are all those mundane Drupal tasks that Drush no longer monopolizes:
From installing Drupal to installing and enabling Drupal modules, to managing your dependencies, you can speed up all these common tasks using Drupal Console.
Also, when it comes to updating Drupal using Drush, you might hit your head against a few inconveniences:
If your Drupal 8 website has custom libraries, as well, (e.g. Search API Solr or Addressess custom libraries) you run the risk to break it once you're updating it via Drush...
7. Final Word: Should You Run Them Together or Stick with One CLI Tool?
My answer is:
“You can run both."
They compliment each other, yet the final decision is yours. Especially when it comes to those functionalities where the 2 CLI tools overlap.
If you do opt for running them together, just use Composer template for Drupal projects.