How to use a custom drush command to help us debug?

Backgroud

  1. Create a drush command is very very very simple! (Do not believe it? Let me show you how later, take a cup of coffee and wait please).
  2. Some developers prefer CLI than open the browser, type a url, enter and watch the output of the dpm() (provided by the Devel module).

I will show you how to debug with a custom drush command. This drush command comes with a custom module.

Create a minimal module foo.

file foo.info:

name = Foo
description = the Foo module
core = 7.x

file foo.module:

<?php

/**
 * @file
 * The foo.module file 
 */

/**
 * The function have a debug, do not eat it without a drush command.
 */
function foo_bar(){
  // Buggy code goes here.
}

Create a minimal drush command foo.

file foo.drush.inc

<?php

/**
 * @file
 * The foo.drush.inc file.
 */

/**
 * Implements hook_drush_command().
 */
function foo_drush_command(){
  return array(
    'foo' => array(
       'description' = 'I'm foo, not fool, eat buuug'
     ),
  );
}

/**
 * The default callback of command foo.
 */
function drush_foo(){
   foo_bar();
}

Happying debugging.

添加新评论

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。