20
CUSTOM DRUSH COMMANDS HOW TO BUILD YOUR OWN CUSTOM DRUSH COMMANDS Created by / Mike Bell @mikebell_

Custom Drush Commands - Drupal Yorkshire

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Custom Drush Commands - Drupal Yorkshire

CUSTOM DRUSH COMMANDSHOW TO BUILD YOUR OWN CUSTOM DRUSH COMMANDS

Created by / Mike Bell @mikebell_

Page 2: Custom Drush Commands - Drupal Yorkshire

WHO?Mike BellTwitter - Drupal.org - Where - CTI Digital - Drupal Technical Architect

@mikebell_digital006

Page 3: Custom Drush Commands - Drupal Yorkshire

WHAT IS DRUSH?Command line utility for Drupal

Used by most Drupal developers, an insanely powerful tool

drupal.org/project/drush

Page 4: Custom Drush Commands - Drupal Yorkshire

ALIAS UPTHE PROBLEM:

Updating aliases across multiple multiple dev machineswithout the user having to go out of their way.

THE SOLUTION:Drush command to keep aliases in sync. Prompt user for

download when using Drush.

Page 5: Custom Drush Commands - Drupal Yorkshire

CAVEATInsecure, Demo, Use at own risk!

Page 6: Custom Drush Commands - Drupal Yorkshire

THE TOOLSDrush...ComposerSymfony YAML

Page 7: Custom Drush Commands - Drupal Yorkshire

COMPOSERWHAT IS IT?

Dependency manager for PHP.

WHY?Used for grabbing Symfony components and creating an

autoloader for them.

Page 8: Custom Drush Commands - Drupal Yorkshire

COMPOSER EXAMPLE

{ "name": "drush/alias_up", "description": "Provide a method to automatically upgrade a user's aliases.drushrc.php using drush itself." "license": "GPL-2.0+", "require": { "symfony/yaml": "2.3.*" }}

Page 9: Custom Drush Commands - Drupal Yorkshire

SYMFONY/YAMLUsed for parsing Yaml files into arrays.

Also used in Drupal 8 core for all config files.

Page 10: Custom Drush Commands - Drupal Yorkshire

EXAMPLE CONFIG FILE

type: git (git/http/https)source: http://mikebell.io/alias.phpupdatefreq: 1 (days)

Page 11: Custom Drush Commands - Drupal Yorkshire

THE HOOKSSymfony Autoloadhook_drush_help()hook_drush_command()aliasup_init()aliasup()aliasup_download()hook_drush_init()aliasup_uninstall()

Page 12: Custom Drush Commands - Drupal Yorkshire

SYMFONY AUTOLOADAuto load the YAML component

require 'vendor/autoload.php'; use Symfony\Component\Yaml\Yaml;

Page 13: Custom Drush Commands - Drupal Yorkshire

HOOK_DRUSH_HELP()Define standard help for the command

Page 14: Custom Drush Commands - Drupal Yorkshire

HOOK_DRUSH_COMMAND()Define your command and the short commands for running

$items['aliasup'] = array( 'description' => 'Update aliases from central server', 'callback' => 'aliasup', 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'examples' => array( 'drush aliasup' => 'Update aliases' ), 'aliases' => array('au'));

Page 15: Custom Drush Commands - Drupal Yorkshire

INSTALL1. Clone Repository2. composer.phar install3. cp example.config.yml../aliasup.config.yml

4. Configure5. Create aliases.drush.php6. drush aui7. drush sa --table

Page 16: Custom Drush Commands - Drupal Yorkshire

USAGEdrush au

Updates the alias file from the remote server

Page 17: Custom Drush Commands - Drupal Yorkshire

UNINSTALLdrush auuni

Removes all the code from the install.

Page 18: Custom Drush Commands - Drupal Yorkshire

LIVE DEMOWhat could go wrong?

Page 19: Custom Drush Commands - Drupal Yorkshire

ANY QUESTIONS?