5 * Topic command and associated hooks.
9 * Implementation of hook_drush_command().
12 * An associative array describing your command(s).
14 function topic_drush_command() {
15 $items['core-topic'] = array(
16 'description' => 'Read detailed documentation on a given topic.',
18 'topic name' => 'The name of the topic you wish to view. If omitted, list all topic descriptions (and names in parenthesis).',
21 'drush topic' => 'Show all available topics.',
22 'drush topic docs-context' => 'Show documentation for the drush context API',
23 'drush docs-context' => 'Show documentation for the drush context API',
25 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
27 'aliases' => array('topic'),
28 'topics' => array('docs-readme'),
35 * Implement hook_drush_help_alter(). Show 'Topics' section on help detail.
37 function topic_drush_help_alter(&$command) {
38 $implemented = drush_get_commands();
39 foreach ($command['topics'] as $topic_name) {
40 // We have a related topic. Inject into the $command so the topic displays.
41 $command['sections']['topic_section'] = 'Topics';
42 $command['topic_section'][$topic_name] = $implemented[$topic_name]['description'];
49 * Show a choice list of available topics and then dispatch to the respective command.
51 * @param string $topic_name
54 function drush_topic_core_topic($topic_name = NULL) {
55 $commands = drush_get_commands();
56 $topics = drush_get_topics();
57 if (isset($topic_name)) {
58 foreach (drush_get_topics() as $key => $topic) {
59 if (strstr($key, $topic_name) === FALSE) {
65 return drush_set_error('DRUSH_NO_SUCH_TOPIC', dt("No topics on !topic found.", array('!topic' => $topic_name)));
67 if (count($topics) > 1) {
69 foreach ($topics as $key => $topic) {
70 $choices[$key] = $topic['description'];
72 natcasesort($choices);
73 if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)', array(5))) {
74 return drush_user_abort();
78 $keys = array_keys($topics);
79 $topic_name = array_pop($keys);
81 return drush_dispatch($commands[$topic_name]);
85 * A command argument complete callback.
88 * Available topic keys.
90 function topic_core_topic_complete() {
91 return array('values' => array_keys(drush_get_topics()));
95 * Retrieve all defined topics
97 function drush_get_topics() {
98 $commands = drush_get_commands();
99 foreach ($commands as $key => $command) {
100 if (!empty($command['topic']) && empty($command['is_alias'])) {
101 $topics[$key] = $command;