function drush_get_commands

8.0.x command.inc drush_get_commands($reset = FALSE)
6.x command.inc drush_get_commands()
7.x command.inc drush_get_commands($reset = FALSE)
3.x command.inc drush_get_commands()
4.x command.inc drush_get_commands()
5.x command.inc drush_get_commands()
master command.inc drush_get_commands($reset = FALSE)

Get a list of all implemented commands. This invokes hook_drush_command().

Return value

Associative array of currently active command descriptors.

6 calls to drush_get_commands()
core_cli_bashrc in commands/core/core.drush.inc
drush_core_help in commands/core/core.drush.inc
This is called if no command or an unknown command is entered.
drush_help_html in commands/core/core.drush.inc
Return an HTML page documenting all available commands and global options.
drush_is_command in includes/command.inc
drush_parse_command in includes/command.inc
Matches a commands array, as returned by drush_get_arguments, with the current command table.

... See full list

File

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

Code

function drush_get_commands() {
  $commands = $available_commands = array();
  $list = drush_commandfile_list();
  foreach ($list as $commandfile => $path) {
    if (drush_command_hook($commandfile, 'drush_command')) {
      $function = $commandfile . '_drush_command';
      $result = $function();
      foreach ((array) $result as $key => $command) {
        // Add some defaults and normalize the command descriptor
        $command += array(
          'command' => $key,
          'command-hook' => $key,
          'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
          'commandfile' => $commandfile,
          'path' => dirname($path),
          'engines' => array(), // Helpful for drush_show_help().
          'callback' => 'drush_command',
          'description' => NULL,
          'arguments' => array(),
          'options' => array(),
          'examples' => array(),
          'aliases' => array(),
          'deprecated-aliases' => array(),
          'extras' => array(),
          'core' => array(),
          'scope' => 'site',
          'drupal dependencies' => array(),
          'drush dependencies' => array(),
          'bootstrap_errors' => array(),
          'hidden' => FALSE,
        );
        // If command callback is correctly named, then fix
        // up the command entry so that drush_invoke will be
        // called.
        if ($command['callback'] != 'drush_command') {
          $required_command_prefix = 'drush_' . $commandfile . '_';
          if ((substr($command['callback'], 0, strlen($required_command_prefix)) == $required_command_prefix)) {
            $command['command-hook'] = substr($command['callback'], strlen($required_command_prefix));
            $command['callback'] = 'drush_command';
          }
          else {
            $command['callback-required-prefix'] = $required_command_prefix;
          }
        }
        // Enforce the no-spaces in command names rule
        if ((!drush_get_option('allow-spaces-in-commands', FALSE)) && (strpos($key, ' ') !== FALSE)) {
          $command['must-replace-spaces'] = TRUE;
        }
        // Temporary:  if there is a dash in the command name,
        // then make a deprecated alias that has a space in the name.
        if (strpos($key, '-') !== FALSE) {
          $command['deprecated-aliases'][] = str_replace('-', ' ', $key);
        }

        // Collect all the commands (without filtering) so we can match non-executable
        // commands, and later explain why they are not executable.
        drush_enforce_requirement_bootstrap_phase($command);
        drush_enforce_requirement_core($command);
        drush_enforce_requirement_drupal_dependencies($command);
        $commands[$key] = $command;
        // For every alias, make a copy of the command and store it in the command list
        // using the alias as a key
        if (isset($command['aliases']) && count($command['aliases'])) {
          foreach ($command['aliases'] as $alias) {
            $commands[$alias] = $command;
            $commands[$alias]['is_alias'] = TRUE;
          }
        }
        // Do the same operation on the deprecated aliases.
        if (isset($command['deprecated-aliases']) && count($command['deprecated-aliases'])) {
          foreach ($command['deprecated-aliases'] as $alias) {
            $commands[$alias] = $command;
            $commands[$alias]['is_alias'] = TRUE;
            $commands[$alias]['deprecated'] = TRUE;
            $commands[$alias]['deprecated-name'] = $alias;
            if ((!drush_get_option('allow-spaces-in-commands', FALSE)) && (strpos($alias, ' ') !== FALSE)) {
              $commands[$alias]['must-not-use-spaces'] = TRUE;
            }
          }
        }

      }
    }
  }

  return drush_set_context('DRUSH_COMMANDS', $commands);
}