Documentation for writing drush commands

Events happening in the community are now at Drupal community events on www.drupal.org.
wonder95's picture

I am working on a site that does a lot of importing data from external sources, and I want to write some drush commands to do this. In looking around, I haven't been able to find any documentation for writing drush commands, such as the available hooks, format and return values for each hook, etc., other that looking at existing code. Once I get everything figured out I will write some documentation (either blog posts or handbook pages), but I don't want to reinvent the wheel if I don't need to (it's very possible I just didn't search well enough). Can anyone point me to some written documentation on writing drush commands?

Thanks.

Comments

Have you looked at

greg.1.anderson's picture

Have you looked at drush.api.php?

also,

moshe weitzman's picture

also, examples/sandwich.drush.inc is our highly documented example. and yes, the core commands serve as decent documentation until someone writes Pro Drush Development.

for data migration, consider using migrate module which is built on top of drush.

@moshe, thanks. I'm in the

wonder95's picture

@moshe, thanks. I'm in the process of writing my script, and I'd like to step through it like I do with module code. I usually use my Komodo debugger with the XDebug helper FF extension. Is there a way to do that with a drush script since it's run from the command line? Judging from here it looks like you can do it with Komodo, too, but I can't figure out what you're calling to get it started.

Thanks.

You have to make sure your

moshe weitzman's picture

You have to make sure your the php.ini that drush uses is configured has remote debugging enabled. Use drush status to identify the location of that php.ini or use php --ini at the command line. Once that is working, turn on listening in komodo and you should get PHP calling into Komodo for every CLi request. I recommend making a 'hello world' tiny php script and practicing with that since drush is unrelated and just can confuse the issue.

I'm running MacPorts, so

wonder95's picture

I'm running MacPorts, so everything for me is installed under /opt/local. When I run php --ini I get

Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File:         (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed:      /opt/local/var/db/php5/php.ini,
/opt/local/var/db/php5/xdebug.ini

and drush status gives me

Drupal version         :  6.19                       
Site URI               :  http://default             
Database driver        :  mysqli                     
Database hostname      :  localhost                  
Database username      :  drupal_user                
Database name          :  ridethis                   
Database               :  Connected                  
Drupal bootstrap       :  Successful                 
Drupal user            :  Anonymous                  
Default theme          :  garland                    
Administration theme   :  garland                    
PHP configuration      :                             
Drush version          :  3.3                        
Drush configuration    :                             
Drupal root            :  /Users/steve/Sites/ridethis
Site path              :  sites/default              
File directory path    :  sites/default/files    

Does the fact that the "Loaded Configuration File" item in php --ini and "PHP configuration" item in drush are empty mean that it's not reading my /opt/local/etc/php5/php.ini? Also, as you can see, I am using a separate xdebug.ini file. That shouldn't be a problem, should it?

Thanks.

Found where CLI php.ini should be

wonder95's picture

After poking around, it looks like the CLI php.ini is usually under something like /etc/php5/cli, so I copied my php.ini to /opt/local/etc/php5, and now the two items I mentioned above that were blank now show /opt/local/etc/php5/php.ini. I then created a tiny helloworld.php file in my Drupal root, opened it in Komodo, set a breakpoint, made sure listening was turned on, and ran the script from the command line, but it's still not stopping at my breakpoint. Is there something else I'm missing?

Thanks.

It works!

wonder95's picture

OK, turns out I already had everything configured properly for xdebug, but per the Xdebug documentation, I had to set the XDEBUG_CONFIG environment variable:

export XDEBUG_CONFIG="idekey=session_name"

Once I did that, I was able to debug my little Hello World script and also my drush script. Woo hoo!!

I just committed

greg.1.anderson's picture

I just committed http://drupal.org/node/987974, which adds some useful content to the drush topic command. Grab drush-HEAD, then run drush topic. There is information there on how to write drush commands, etc.

drush

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: