Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / topic.drush.inc
1 <?php
2
3 /**
4  * @file
5  *   Topic command and associated hooks.
6  */
7
8 /**
9  * Implementation of hook_drush_command().
10  *
11  * @return
12  *   An associative array describing your command(s).
13  */
14 function topic_drush_command() {
15   $items['core-topic'] = array(
16     'description' => 'Read detailed documentation on a given topic.',
17     'arguments' => array(
18       'topic name' => 'The name of the topic you wish to view. If omitted, list all topic descriptions (and names in parenthesis).',
19     ),
20     'examples' => array(
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',
24     ),
25     'bootstrap' => DRUSH_BOOTSTRAP_NONE,
26     'remote-tty' => TRUE,
27     'aliases' => array('topic'),
28     'topics' => array('docs-readme'),
29   );
30
31   return $items;
32 }
33
34 /**
35  * Implement hook_drush_help_alter(). Show 'Topics' section on help detail.
36  */
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'];
43   }
44 }
45
46 /**
47  * A command callback.
48  *
49  * Show a choice list of available topics and then dispatch to the respective command.
50  *
51  * @param string $topic_name
52  *   A command name.
53  */
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) {
60         unset($topics[$key]);
61       }
62     }
63   }
64   if (empty($topics)) {
65     return drush_set_error('DRUSH_NO_SUCH_TOPIC', dt("No topics on !topic found.", array('!topic' => $topic_name)));
66   }
67   if (count($topics) > 1) {
68     // Show choice list.
69     foreach ($topics as $key => $topic) {
70       $choices[$key] = $topic['description'];
71     }
72     natcasesort($choices);
73     if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)', array(5))) {
74       return drush_user_abort();
75     }
76   }
77   else {
78     $keys = array_keys($topics);
79     $topic_name = array_pop($keys);
80   }
81   return drush_dispatch($commands[$topic_name]);
82 }
83
84 /**
85  * A command argument complete callback.
86  *
87  * @return
88  *   Available topic keys.
89  */
90 function topic_core_topic_complete() {
91   return array('values' => array_keys(drush_get_topics()));
92 }
93
94 /**
95  * Retrieve all defined topics
96  */
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;
102     }
103   }
104   return $topics;
105 }