Drupal - How to adapt the name of a custom Drush command?

You would have to change a couple of things:

/**
 * Implements hook_drush_command().
 */
function drush_content_types_drush_command() {
  $items['mijn-contenttypes-lijst'] = array(
    'description' => dt("Show a list of available content types."),
    'aliases' => array('mcl'),
  );
  return $items;
}

The array key under $items and the "aliases" value under that need changed. The array key is used to identify the callback to invoke when using the drush command or alias. The callback, for whatever reason, doesn't start with the command file prefix but rather starts with "drush" and then the command file prefix and then the array key listed above replacing the dashes with underscores. So the second (callback) function would look like...

/**
 * Callback for the content-type-list command.
 */
function drush_drush_content_types_mijn_contenttypes_lijst() {
  $content_types = array_keys(node_type_get_types());
  sort($content_types);

  drush_print(dt("Machine name"));
  drush_print(implode("\r\n", $content_types));
}

Making those changes should give you what you want. More information about creating your own drush commands can be found here: Command Authoring


Using the code in my answer to "How can I get a list of content types with drush?", you can do something like this:

The name of your file is MY_MODULE_NAME.drush.inc

<?php
/**
 * @file
 * Drush commands related to Content Types.
 */

/**
* Implements hook_drush_command().
*/
function MY_MODULE_NAME_drush_command() {
  $items['MY-DRUSH-CMD'] = array(
    'description' => dt("Show a list of available content types."),
    'aliases' => array('MD-CMD', 'another-alias', 'and-other'),
  );
  return $items;
}

/**
 * Callback for the MY-DRUSH-CMD command.
 * See here that you must change the - by a _
 * (MY-DRUSH-CMD by MY_DRUSH_CMD) in the callback function
 */
function drush_MY_MODULE_NAME_MY_DRUSH_CMD() {
  $VAR = array_keys(node_type_get_types());
  sort($VAR);

  drush_print(dt("Machine name"));
  drush_print(implode("\r\n", $VAR));
}

In the aliases array you can add more aliases.

Install the module, run drush cc drush to clear the drush cache and use the command like this:

You can use:

drush MY-DRUSH-CMD
drush MD-CMD
drush another-alias
drush and-other

References:

  • How to Create Your Own Drush Command
  • How to write drush commands and hooks
  • Drush Integration for your modules

See also the drushify command on drupal.org.

drushify is a simple code generator that creates a skeleton Drush commandfile template for the module you specify.

Installation

drush dl drushify

Usage

drush @site drushify modulename

Tags:

Drush

7