diff --git a/commands/core/help.drush.inc b/commands/core/help.drush.inc index 04cd6e30a5..a537e5ee45 100644 --- a/commands/core/help.drush.inc +++ b/commands/core/help.drush.inc @@ -347,7 +347,7 @@ function drush_core_help() { drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION); $implemented = drush_get_commands(); ksort($implemented); - $command_categories = drush_help_categorize($implemented); + $command_categories = drush_commands_categorize($implemented); $visible = drush_help_visible($command_categories); // If the user specified --filter w/out a value, then @@ -461,94 +461,6 @@ function drush_help_listing_print($command_categories, $format) { } } -/** - * Organize commands into categories - */ -function drush_help_categorize($implemented) { - $command_categories = array(); - $category_map = array(); - foreach ($implemented as $key => $candidate) { - if ((!array_key_exists('is_alias', $candidate) || !$candidate['is_alias']) && !$candidate['hidden']) { - $category = $candidate['category']; - // If we have decided to remap a category, remap every command - if (array_key_exists($category, $category_map)) { - $category = $category_map[$category]; - } - if (!array_key_exists($category, $command_categories)) { - $title = drush_command_invoke_all('drush_help', "meta:$category:title"); - $alternate_title = ''; - if (!$title) { - // If there is no title, then check to see if the - // command file is stored in a folder with the same - // name as some other command file (e.g. 'core') that - // defines a title. - $alternate = basename($candidate['path']); - $alternate_title = drush_command_invoke_all('drush_help', "meta:$alternate:title"); - } - if (!empty($alternate_title)) { - $category_map[$category] = $alternate; - $category = $alternate; - $title = $alternate_title; - } - $command_categories[$category]['title'] = empty($title) ? '' : $title[0]; - $summary = drush_command_invoke_all('drush_help', "meta:$category:summary"); - if ($summary) { - $command_categories[$category]['summary'] = $summary[0]; - } - } - $candidate['category'] = $category; - $command_categories[$category]['commands'][$key] = $candidate; - } - } - - // Make sure that 'core' is always first in the list - $core_category = array('core' => $command_categories['core']); - unset($command_categories['core']); - - // Post-process the categories that have no title. - // Any that have fewer than 4 commands go into a section called "other". - $processed_categories = array(); - $misc_categories = array(); - $other_commands = array(); - $other_categories = array(); - foreach ($command_categories as $key => $info) { - if (empty($info['title'])) { - $one_category = $key; - if (count($info['commands']) < 4) { - $other_commands = array_merge($other_commands, $info['commands']); - $other_categories[] = $one_category; - } - else { - $info['title'] = dt("All commands in !category", array('!category' => $key)); - $misc_categories[$one_category] = $info; - } - } - else { - $processed_categories[$key] = $info; - } - } - $other_category = array(); - if (!empty($other_categories)) { - $other_category[implode(',', $other_categories)] = array('title' => dt("Other commands"), 'commands' => $other_commands); - } - asort($processed_categories); - asort($misc_categories); - $command_categories = array_merge($core_category, $processed_categories, $misc_categories, $other_category); - - // If the user specified --sort, then merge all of the remaining - // categories together - if (drush_get_option('sort', FALSE)) { - $combined_commands = array(); - foreach ($command_categories as $key => $info) { - $combined_commands = array_merge($combined_commands, $info['commands']); - } - $command_categories = array('all' => array('commands' => $combined_commands, 'title' => dt("Commands:"))); - } - - return $command_categories; -} - - /** * Return an HTML page header. */ diff --git a/includes/command.inc b/includes/command.inc index 668768f727..f503fc95ae 100644 --- a/includes/command.inc +++ b/includes/command.inc @@ -1047,6 +1047,93 @@ function drush_get_commands($reset = FALSE) { return $commands; } +/** + * Organize commands into categories. Used by help listing and core-cli. + */ +function drush_commands_categorize($implemented) { + $command_categories = array(); + $category_map = array(); + foreach ($implemented as $key => $candidate) { + if ((!array_key_exists('is_alias', $candidate) || !$candidate['is_alias']) && !$candidate['hidden']) { + $category = $candidate['category']; + // If we have decided to remap a category, remap every command + if (array_key_exists($category, $category_map)) { + $category = $category_map[$category]; + } + if (!array_key_exists($category, $command_categories)) { + $title = drush_command_invoke_all('drush_help', "meta:$category:title"); + $alternate_title = ''; + if (!$title) { + // If there is no title, then check to see if the + // command file is stored in a folder with the same + // name as some other command file (e.g. 'core') that + // defines a title. + $alternate = basename($candidate['path']); + $alternate_title = drush_command_invoke_all('drush_help', "meta:$alternate:title"); + } + if (!empty($alternate_title)) { + $category_map[$category] = $alternate; + $category = $alternate; + $title = $alternate_title; + } + $command_categories[$category]['title'] = empty($title) ? '' : $title[0]; + $summary = drush_command_invoke_all('drush_help', "meta:$category:summary"); + if ($summary) { + $command_categories[$category]['summary'] = $summary[0]; + } + } + $candidate['category'] = $category; + $command_categories[$category]['commands'][$key] = $candidate; + } + } + + // Make sure that 'core' is always first in the list + $core_category = array('core' => $command_categories['core']); + unset($command_categories['core']); + + // Post-process the categories that have no title. + // Any that have fewer than 4 commands go into a section called "other". + $processed_categories = array(); + $misc_categories = array(); + $other_commands = array(); + $other_categories = array(); + foreach ($command_categories as $key => $info) { + if (empty($info['title'])) { + $one_category = $key; + if (count($info['commands']) < 4) { + $other_commands = array_merge($other_commands, $info['commands']); + $other_categories[] = $one_category; + } + else { + $info['title'] = dt("All commands in !category", array('!category' => $key)); + $misc_categories[$one_category] = $info; + } + } + else { + $processed_categories[$key] = $info; + } + } + $other_category = array(); + if (!empty($other_categories)) { + $other_category[implode(',', $other_categories)] = array('title' => dt("Other commands"), 'commands' => $other_commands); + } + asort($processed_categories); + asort($misc_categories); + $command_categories = array_merge($core_category, $processed_categories, $misc_categories, $other_category); + + // If the user specified --sort, then merge all of the remaining + // categories together + if (drush_get_option('sort', FALSE)) { + $combined_commands = array(); + foreach ($command_categories as $key => $info) { + $combined_commands = array_merge($combined_commands, $info['commands']); + } + $command_categories = array('all' => array('commands' => $combined_commands, 'title' => dt("Commands:"))); + } + + return $command_categories; +} + function drush_command_defaults($key, $commandfile, $path) { $defaults = array( 'command' => $key,