function drush_dispatch

8.0.x command.inc drush_dispatch($command, $arguments = array())
6.x command.inc drush_dispatch($command, $arguments = array())
7.x command.inc drush_dispatch($command, $arguments = array())
3.x drush.inc drush_dispatch($command = NULL)
4.x command.inc drush_dispatch($command, $arguments = array())
5.x command.inc drush_dispatch($command, $arguments = array())
master command.inc drush_dispatch($command, $arguments = array())

Dispatch a given set of commands. Modules can add commands by implementing hook_drush_command().

Parameters

Command whose callback you want to call, defaults to current command.:

1 call to drush_dispatch()
drush_main in ./drush.php
The main Drush function.

File

includes/drush.inc, line 21
The drush API implementation and helpers.

Code

function drush_dispatch($command = NULL) {
  $command = ($command) ? $command : drush_get_command();
  $return = FALSE;

  if ($command) {
    // Add command-specific options, if applicable
    drush_command_default_options($command);

    if (isset($command['must-replace-spaces'])) {
      $required_name = str_replace(' ', '-', $command['command']);
      drush_set_error(dt('Notice: "!name" must be renamed to "!requiredname" in order to work with this version of drush.  If you are the maintainer for the module that defines this command, please rename it immediately.  If you are a user of this command, you may enable spaces in commands for a while by setting "allow-spaces-in-commands" in your drush configuration file.  See example.drushrc.php.', array('!name' => $command['command'], '!requiredname' => $required_name)));
      return FALSE;
    }
    // Print a warning if someone tries to use a deprecated alias.
    if (isset($command['deprecated'])) {
      drush_log(dt('Warning: The command name "!deprecated" is deprecated.  Please use a recommended form instead (!recommended).', array('!deprecated' => $command['deprecated-name'], '!recommended' => implode(',', array_merge(array($command['command']), $command['aliases'])))), 'warning');
      if (isset($command['must-not-use-spaces'])) {
        drush_set_error(dt('You may enable spaces in commands for a while by setting "allow-spaces-in-commands" in your drush configuration file.  See example.drushrc.php.', array('!name' => $command['command'], '!requiredname' => $required_name)));
        return FALSE;
      }
    }
    // Print a warning if a command callback function is misnamed
    if (isset($command['callback-required-prefix'])) {
      drush_log(dt('Warning: The command callback function !callback has a deprecated name.  It must begin with !requiredprefix.  Skipping hook functions.', array('!callback' => $command['callback'], '!requiredprefix' => $command['callback-required-prefix'])));
    }
    // Call the callback function of the active command.
    // TODO:  If we make the required prefix actually required rather than just emitting a
    // warning, then this could become a direct call to drush_command (all commands with
    // the required prefix will now go through drush_command + drush_invoke).
    $return = call_user_func_array($command['callback'], $command['arguments']);
  }

  // prevent a '1' at the end of the output
  if ($return === TRUE) {
    $return = '';
  }

  // Add a final log entry, just so a timestamp appears.
  drush_log(dt('Command dispatch complete'), 'notice');

  return $return;
}