5

When you go to create new drush commands you can define the 'description' element inside the hook_drush_command(), and if you use drush help your_command you will see this description as output.

function onlyone_drush_command() {
  $items['onlyone-list'] = array(
    'description' => dt("List the configured content types to have Only One node."),
    'aliases' => array('ol'),
    'examples' => array(
      'drush onlyone-list' => dt("List the configured content types to have Only One node."),
    ),
  );
  return $items;
}

Command:

drush help ol

Output:

List the configured content types to have Only One node.

Examples:
 drush onlyone-list  List the configured content types to have Only One node.

Aliases: ol

But once you implement the hook_drush_help() and you use drush help your_command you will see the description defined inside this hook and you'll never see again the description defined inside hook_drush_command().

function onlyone_drush_help($section) {
  switch ($section) {
    case 'drush:onlyone-list':
      return dt('This is from help');
  }
}

Command:

drush help ol

Output:

This is from help

Examples:
drush onlyone-list  List the configured content types to have Only One node.

Aliases: ol

So, why to use hook_drush_help() when we have 'description' in hook_drush_command()?

2

The answer is context.

The command data pulled from hook_drush_command() is used when listing of all available drush commands with the command:

drush

So if a user is curious, "What drush commands do I have, and what do they do?" hook_drush_command() would provide that snippet. This could be useful for a short description in a directory of commands.

If a user is curious about a specific command:

drush help my_command

That's where hook_drush_help() would be more applicable as it can provide a detailed description that is only about that command queried.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.