function drush_parse_command

8.0.x drush_parse_command()
6.x drush_parse_command()
7.x drush_parse_command()
3.x drush_parse_command()
4.x drush_parse_command()
5.x drush_parse_command()
master drush_parse_command()

Matches a commands array, as returned by drush_get_arguments, with the current command table.

Note that not all commands may be discoverable at the point-of-call, since Drupal modules can ship commands as well, and they are not available until after bootstrapping.

drush_parse_command returns a normalized command descriptor, which is an associative array. Some of its entries are:

  • callback arguments: an array of arguments to pass to the calback.
  • description: description of the command.
  • arguments: an array of arguments that are understood by the command. for help texts.
  • required-arguments: The minimum number of arguments that are required, or TRUE if all are required.
  • options: an array of options that are understood by the command. for help texts.
  • examples: an array of examples that are understood by the command. for help texts.
  • scope: one of 'system', 'project', 'site'.
  • bootstrap: drupal bootstrap level (depends on Drupal major version). -1=no_bootstrap.
  • core: Drupal major version required.
  • drupal dependencies: drupal modules required for this command.
  • drush dependencies: other drush command files required for this command.
  • handle-remote-commands: set to TRUE if `drush @remote mycommand` should be executed locally rather than remotely dispatched. When this mode is set, the target site can be obtained via: drush_get_context('DRUSH_TARGET_SITE_ALIAS')
  • strict-option-handling: set to TRUE if drush should strictly separate local command cli options from the global options. Usually, drush allows global cli options and command cli options to be interspersed freely on the commandline. For commands where this flag is set, options are separated, with global options comming before the command names, and command options coming after, like so: drush --global-options command --command-options In this mode, the command options are no longer available via drush_get_option(); instead, they can be retrieved via: $args = drush_get_original_cli_args_and_options(); $args = drush_get_context('DRUSH_COMMAND_ARGS', array()); In this case, $args will contain the command args and options literally, exactly as they were entered on the command line, and in the same order as they appeared.
3 calls to drush_parse_command()
drush_preflight_command_dispatch in includes/
Handle any command preprocessing that may need to be done, including potentially redispatching the command immediately (e.g. for remote commands).
drush_redispatch_get_options in includes/
Get the options that were passed to the current command.
_drush_bootstrap_and_dispatch in ./drush.php


includes/, line 1131
The drush command engine.


function drush_parse_command() {
  $args = drush_get_arguments();
  $command = FALSE;

  // Get a list of all implemented commands.
  $implemented = drush_get_commands();
  if (isset($implemented[$args[0]])) {
    $command = $implemented[$args[0]];
    $arguments = array_slice($args, 1);

  // We have found a command that matches. Set the appropriate values.
  if ($command) {
    // Special case. Force help command if --help option was specified.
    if (drush_get_option('help')) {
      $arguments = array($command['command']);
      $command = $implemented['help'];
      $command['arguments'] = $arguments;
    else {
      _drush_prepare_command($command, $arguments);
  return $command;