Drush 9 Under the Spotlight! What's New and Improved?

What to expect from the “shiny new” Drush 9? The very first major Drush re-write in years (since 2008, to be more specific)!!! What's new and improved and what remains unchanged? How will this new version of Drush speed up your dev tasks even more and how much time and effort do you need to invest in getting into gear with it?

Embracing a Composer-centric philosophy... switching to annotated Drush 9 commands... gradually moving away from CLI code to Symfony Console... And these are but some of Drush 9's buzz-generating changes (and in this respect, the 2 Drush maintainers' session, Drush 9 - Lean and Modern, at DrupalCon Vienna, is THE source of information to go to).

In order to hand pick and bunch up only the truly groundbreaking ones, I've dug deeper and deeper and here I am now! Ready to bring the “freshly painted” Drush 9 under the spotlight for you!

I'll be exposing both its high-impact novelties and those familiar aspects of Drush 8 which remain unchanged in Drush 9. So, let's get right into it, shall we?

 

1. From Drush Make to a Composer-Based Site Building

By far one of the main changes brought to this ground-up rewriting of Drush has been embracing the Composer-centric workflow.

And it encourages you, the Drupal developer and Drupal site builder, to do the same!

If it's a fresh new Drupal project that you're setting up you can forget all about relying on good old Drush Make! You'll need to... convert to Composer when using Drush 9 to build your website! 

So, here's how you start your new Composer web project:

  1. you go to drupal-composer/drupal-project on GitHub, which will automatically group together your Drupal codebase and inject the Drush command line tool right into your project
  2. then you install a new Drush 9 composer based tool: drush launcher

Just put the latter anywhere in your path and you're good to go. 

And this is how you start a new Composer web project using Drush 9.

 

2. Turn Your Current Drupal 8 Site Into a Composer-Built One 

There's no other way around it! You need to turn your existing “bare” Drupal site into a Composer-based one.

And you have 2 options for converting your Drupal site:

  1. you enter the make-convert Drush 8 command 
  2. you use the new truly groundbreaking drush composer-generate command in Drush 9

But Do I really need to convert to Composer?

A more than legitimate question, indeed! Why should you jump on this Composer site building trend after all? Just because the Drush maintainers tell you to?

Here are 2 good reasons:

  1. Composer (via composer install) will practically bring together the whole codebase you'll need (instead of you using the conventional Drupal code assembly commands)

     
  2. … and this is a particularly handy and time-saving convenience helping you out with your dependency management in Drupal (and there's no denying it: Drupal modules have been bundling up more and more dependencies which, at some point, become challenging to manage efficiently)

     

3. Some of The “Legendary” Drush Commands Are Still There

That's right! Even if major changes have been made, Drush's maintainers did not “lay a finger on” some of the commands that we're all so familiar with already, such as:

  • uli, rsync, sql-sync
  • drush pml –format=json
  • pm-enable & pmu

… and more!

 

4. Modernizing The Drush 9 Commands Meant Removing Some of Them

Some of the old Drush commands did not make it to Drush 9. They simply didn't comply with the very principles that the command-line shell has been re-written by. 

And here are some of the commands that the Drush maintainers have got rid off:

  • pm-update, dl
  • -n is –non-interactive
  • make, archive, qd

… and the list goes on.

 

5. Give a Warm Welcome to The Brand New Drush 9 Commands!

When “dusty”, outdated Drush commands quit the stage some new ones get ready to... steal the spotlight.

And here are some of the “novelties” that Drush 9 promises to ease your work as a developer with:

 

  • you get to run your Drush commands right from your project root

     
  • you have yml config and aliases replacing the old php-based ones

     
  • please welcome: drush generate! A Drush 9 command that Drush maintainers have set great store by as one of the most “revolutionary” new commands in Drush 9

     
  • Config Split, a configuration technique which will practically enable you to run different configurations, each one specific to one of your multiple environments and which won't interfere with one another; a major improvement to the Drupal 8 configuration management system!

     

6. Generate Code: The “Superstar” Tool Under Drush 9's Tool-Belt

Enter “generate code”, the piece of functionality added to Drush 9 which will make your work as a Drupal developer so much more enjoyable! 

It does precisely what its name says: it generates code!

Now here are some “magic words”, I mean 2 of the commands that you can use, which it can process and “execute”:

  • drush gen module-standard, which practically puts together a new module for you and “pre-populates” it with lots of basic code that you'll only need to customize later on; a major time-saver!
  • drush gen content-entity, which will create a new content-entity for you

     

7. Enter A New Authoring Commands Format!

In other words:

  • welcome classes type of commands and bid farewell to procedural .inc files!
  • welcome annotated commands!

Since Drush 9 is object-oriented and since, therefore, you'll be joggling classes from now on, these very classes:

  • incorporate their own dependencies now
  • are referred to by tagged services 

Also: welcome a new heavy load of handy Drush hooks, which (surprise, surprise!) are annotated commands (in a class) themselves, too!

And it's here that I shall turn off the spotlight (for now) I've put on Drush 9! I did gather much more valuable information after my little “investigation” of this new version of Drush, yet... I'll keep the rest of the “goodies” for another post.

Don't be shy to let me know what you think so far about this release. Which one of its new features/improvements are you most excited about? Whether you're being skeptical about adopting some of them into your workflow etc.