function drush_core_help

8.0.x help.drush.inc drush_core_help()
6.x help.drush.inc drush_core_help()
7.x help.drush.inc drush_core_help()
3.x core.drush.inc drush_core_help()
4.x help.drush.inc drush_core_help()
5.x help.drush.inc drush_core_help()
master help.drush.inc drush_core_help($name = '')

Command callback for help command. This is the default command, when none other has been specified.

File

commands/core/help.drush.inc, line 343

Code

function drush_core_help() {
  $commands = func_get_args();
  $format = drush_get_option('format');

  if (empty($commands)) {
    // For speed, only bootstrap up to DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION.
    drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
    $implemented = drush_get_commands();
    ksort($implemented);
    $command_categories = drush_commands_categorize($implemented);
    $visible = drush_help_visible($command_categories);

    // If the user specified --filter w/out a value, then
    // present a choice list of help categories.
    if (drush_get_option('filter', FALSE) === TRUE) {
      $help_categories = array();
      foreach ($command_categories as $key => $info) {
        $description = $info['title'];
        if (array_key_exists('summary', $info)) {
          $description .= ": " . $info['summary'];
        }
        $help_categories[$key] = $description;
      }
      $result = drush_choice($help_categories, 'Select a help category:');
      if (!$result) {
        return drush_user_abort();
      }
      drush_set_option('filter', $result);
    }
    // Filter out categories that the user does not want to see
    $filter_category = drush_get_option('filter');
    if (!empty($filter_category) && ($filter_category !== TRUE)) {
      if (!array_key_exists($filter_category, $command_categories)) {
        return drush_set_error('DRUSH_NO_CATEGORY', dt("The specified command category !filter does not exist.", array('!filter' => $filter_category)));
      }
      $command_categories = array($filter_category => $command_categories[$filter_category]);
    }

    if ($format == 'html') {
      drush_print(drush_help_html_header());
    }

    // Make a fake command section to hold the global options, then print it.
    $global_options_help = drush_global_options_command(TRUE);
    if (!in_array($format, array('html', 'var_export', 'json')) && !drush_get_option('filter')) {
      drush_print_help($global_options_help);
    }

    if ($format == 'json' || $format == 'var_export') {
      // Print giant array, and set backend_result. We do it this way because this command
      // isn't yet fully compliant with outputformat system. To do so, we need to deal with
      // the fact that this command varies output significantly when showing help for one
      // command versus a listing. We also have oddball HTML format.
      drush_print(drush_format($command_categories, 'commands'));
      drush_backend_set_result($command_categories);
      return NULL;
    }
    else {
      // HTML and CLI command listing (in a table).
      drush_help_listing_print($command_categories, $format);

      if ($format == 'html') {
        // Print global options and long-form help for all commands.
        drush_print(drush_help_html_global_options($global_options_help));
        drush_print(drush_help_html($visible));
      }
    }

    // Newline-delimited list for use by other scripts. Set the --pipe option.
    if (drush_get_option('pipe')) {
      drush_print_pipe(implode("\n", array_keys($visible)));
    }
    return;
  }
  else {
    $result = TRUE;
    while ((count($commands) > 0) && !drush_get_error()) {
      $result = drush_show_help(array_shift($commands));
    }
    return $result;
  }

  return drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt('Invalid command !command.', array('!command' => implode(" ", $commands))));
}