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())

Given a command record, dispatch it as if it were the original command. Executes in the currently bootstrapped site using the current option contexts. Note that drush_dispatch will not bootstrap any further than the current command has already bootstrapped; therefore, you should only invoke commands that have the same (or lower) bootstrap requirements.

Parameters

command: A full $command such as returned by drush_get_commands(), or a string containing the name of the command record from drush_get_commands() to call.

arguments: An array of argument values.

See also

drush_topic_docs_topic().

Related topics

3 calls to drush_dispatch()
BaseBoot::bootstrap_and_dispatch in lib/Drush/Boot/BaseBoot.php
Main entrypoint to bootstrap the selected CMS and execute the selected command.
drush_invoke in includes/command.inc
Invokes a Drush API call, including all hooks.
drush_topic_core_topic in commands/core/topic.drush.inc
A command callback.

File

includes/command.inc, line 150
The drush command engine.

Code

function drush_dispatch($command, $arguments = array()) {
  drush_set_command($command);
  $return = FALSE;

  if ($command) {
    // Add arguments, if this has not already been done.
    // (If the command was fetched from drush_parse_command,
    // then you cannot provide arguments to drush_dispatch.)
    if (empty($command['arguments'])) {
      _drush_prepare_command($command, $arguments);
    }

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

    // Test to see if any of the options in the 'cli' context
    // are not represented in the command structure.
    if ((_drush_verify_cli_options($command) === FALSE) || (_drush_verify_cli_arguments($command) === FALSE)) {
      return FALSE;
    }

    // Give command files an opportunity to alter the command record
    drush_command_invoke_all_ref('drush_command_alter', $command);

    // Include and validate command engines.
    if (drush_load_command_engines($command) === FALSE) {
      return FALSE;
    }

    // Do tilde expansion immediately prior to execution,
    // so that tildes are passed through unchanged for
    // remote commands and other redispatches.
    drush_preflight_tilde_expansion($command);

    // Call the callback function of the active command.
    $return = call_user_func_array($command['callback'], $command['arguments']);
  }

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

  return $return;
}