This week we're releasing a new series, Coding for Drush. If you've ever used Drush, and wondered how you can create your own custom Drush commands, then this series is right up your alley. When I sat down to start planning the content for our recent Coding for Views series I found myself in a position where I needed to quickly generate a bunch of random data for a custom module’s database table, so that when querying the table with views there would be something there. If you’re working with nodes or other standard content bits the Devel module provides a great tool for generating random content. That didn’t work in this case though, with my custom database tables, and instead of spending a couple of hours entering dummy data into the table I whipped together a quick drush script to do it for me. Quicker, and easily repeatable.
I then proceeded to plug away at writing content for the Coding for Views series. A couple hours in it dawned on me, I should do the same for Drush since it’s fresh in my head and I just wrote this great, and yet super simple, example. And thus the Coding for Drush series was born.
For the uninitiated 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. Drush commands are really just simple PHP scripts in many cases, with the added benefit of running inside a fully (or partially) bootstrapped Drupal instance. Meaning your script can take advantage of all the Drupal API’s and more importantly it knows about the data that makes up your specific site.
Sometimes though 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 commands
- How to output data from our command’s using some of the helper functions built in to drush
- Generate a bunch of random database records with drush
- Passing arguments to a command
- Passing options to a command
- Prompting the user for input while your command is executing
- What drush make files are, and how to create and use them
And this is just the tip of the iceberg of what you can do with drush. Join us for the journey with our first four videos in the series.
- Overview of the Coding for Drush Series (FREE)
- What are Drush Commands? (FREE)
- Find Drush Documentation and Additional Resources
- Implement hook_drush_command
We'll be releasing this throughout the month of December, so keep your eyes open every Wednesday for more videos.
Add new comment