Gbyte blog: Creating Drush 9 commands and porting legacy commands
Upgrading to Drush 9
Drush should be installed and updated through composer. There is no stable Drush 9 version yet, so the development version must be used. Updating to the development version of Drush 9 is a simple as typing:
$ composer require drush/drush:dev-master
Porting your Drush commands to Drush 9
Porting the commands is a semi-automatic process: There is a command that will generate the required files and class structure for you. To start the wizard, just type:
$ drush generate drush-command-file -l dev
Drush will ask you for the module's machine name and for the optional path to the legacy Drush command file (the one that has your commands, ending with .drush.inc). You will have to provide the absolute path.
drush.services.yml
This is the file your Drush command definition goes into. Do not use your module's regular services.yml as you might have done in Drush 8 or else you will confuse the legacy Drush which will lead to a PHP error like this:
Fatal error: Class 'Drush\Commands\DrushCommands' not found in MyModuleCommands.
Use the dedicated drush.services.yml file in your module's root directory instead.
The file should look like this: