Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Overview of the Coding for Drush Series

0 (0 Likes / 0 Dislikes)
[Drupalize.me] [Learn Drupal] [♫ Music playing ♫] [Overview of the Coding for Drush Series] [Coding for Drush, Chapter 1 with Joe Shindelar] Drush, or the Drupal Shell, is a powerful command-line application that makes it really easy for Drupal developers to interact with a full Drupal environment from their command line and do things like write scripts to help automate certain workflows, install modules, automate deployment. All kinds of different things that we want to do with Drupal, but don't necessarily want a user interface to do it. In this series, we're going to look at how you can extend Drush's functionality by writing your own Drush commands. We'll start by talking about what a command is, what arguments for a command are, and what options for a command are, and how arguments and options differ from one another. Throughout the course of this series, we're going to work on writing a command that extends the functionality of our Databasics Module. We want a command that a user can run that will generate a bunch of random content and stick it into the databasics table so that we can have some dummy data for testing. In order to do that, we're going to start by creating a special command file in the Databasics Module. These are specially named files that Drush will find and, in which, they'll look for an implementation of hook_drush_command. We'll use hook_drush_command in order to tell Drush things like the name of our command, a description for the command. We're also going to use it to tell Drush about the arguments that someone could provide for the command. In addition to that, we can use hook_drush_command in order to tell Drush about the arguments that our command provides. In our case, our command is going to take an argument for the number of records that it should generate. We'll also talk about specifying options for a Drush command. In our case, we want users to be able to type the command at the command line and add a dash, dash, purge (--purge) flag. When they do so, what we want to do is slightly modify the way that the command works. So when the --purge flag is present, we want the command to truncate all of the records that exist in the table before generating new ones. We're also going to look at different ways that you can prompt the user for input from within your Drush command. Even though our Drush command is something that gets run from the terminal, we still have to think about things like user experience. So we'll spend a little bit of time talking about how we can provide help and additional documentation for our command. It'd be nice if we could tie into the built-in Drush help system so that when somebody asks Drush for help about our command, we can tell them how it works. After completing this series, you should understand a lot more about the power of Drush, and how to write your own commands in order to take advantage of some of that and augment your own workflow. Hopefully, you'll also learn a bit about the Drush API, and how to make use of some of the functions within it in order to make your output more friendly, to provide help text for your users, and so forth. So let's go ahead and get started learning about writing our own Drush commands.

Video Details

Duration: 2 minutes and 57 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 58
Posted by: drupalizeme on Nov 29, 2012

Drush is one of the coolest tools available for Drupal developers. It provides all sorts of commands for assisting in Drupal development, automating workflows and in general making it easier to script various parts of the drupal workflow. But sometimes the commands that come with drush or those available from other modules just don’t quite cut it. Sometimes we need to automate things that are specific to our own site. Drush commands can also be really useful for quick one off data migration tasks and other things that writing a whole module for might just be overkill. In this series we’re going to learn about:


What a drush command is and where drush finds the commands that it can use
How to use hook_drush_command in order to tell drush that we want to provide new com

Caption and Translate

    Sign In/Register for Dotsub to translate this video.