Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / help.drush.inc
1 <?php
2
3 /**
4  * Implementation of hook_drush_help().
5  *
6  * This function is called whenever a drush user calls
7  * 'drush help <name-of-your-command>'
8  *
9  * @param
10  *   A string with the help section (prepend with 'drush:')
11  *
12  * @return
13  *   A string with the help text for your command.
14  */
15 function help_drush_help($section) {
16   switch ($section) {
17     case 'drush:help':
18       return dt("Drush provides an extensive help system that describes both drush commands and topics of general interest.  Use `drush help --filter` to present a list of command categories to view, and `drush topic` for a list of topics that go more in-depth on how to use and extend drush.");
19   }
20 }
21
22 /**
23  * Implementation of hook_drush_command().
24  *
25  * In this hook, you specify which commands your
26  * drush module makes available, what it does and
27  * description.
28  *
29  * Notice how this structure closely resembles how
30  * you define menu hooks.
31  *
32  * @return
33  *   An associative array describing your command(s).
34  */
35 function help_drush_command() {
36   $items = array();
37
38   $items['help'] = array(
39     'description' => 'Print this help message. See `drush help help` for more options.',
40     'bootstrap' => DRUSH_BOOTSTRAP_NONE,
41     'allow-additional-options' => array('helpsingle'),
42     'options' => array(
43       'sort' => 'Sort commands in alphabetical order. Drush waits for full bootstrap before printing any commands when this option is used.',
44       'filter' => array(
45         'description' => 'Restrict command list to those commands defined in the specified file. Omit value to choose from a list of names.',
46         'example-value' => 'category',
47         'value' => 'optional',
48       ),
49     ),
50     'arguments' => array(
51       'command' => 'A command name, or command alias.',
52     ),
53     'examples' => array(
54       'drush' => 'List all commands.',
55       'drush --filter=devel_generate' => 'Show only commands defined in devel_generate.drush.inc',
56       'drush help pm-download' => 'Show help for one command.',
57       'drush help dl' => 'Show help for one command using an alias.',
58       'drush help --format=html' => 'Show an HTML page detailing all available commands.',
59       'drush help --format=json' => 'All available comamnds, in a machine parseable format.',
60     ),
61     // Use output format system for all formats except the default presentation.
62     'outputformat' => array(
63       'default' => 'table',
64       'field-labels' => array('name' => 'Name', 'description' => 'Description'),
65       'output-data-type' => 'format-table',
66     ),
67     'topics' => array('docs-readme'),
68   );
69   return $items;
70 }
71
72
73 /**
74  * Command argument complete callback.
75  *
76  * For now, this can't move to helpsingle since help command is the entry point for both.
77  *
78  * @return
79  *   Array of available command names.
80  */
81 function core_help_complete() {
82   return array('values' => array_keys(drush_get_commands()));
83 }
84
85 /**
86  * Command callback for help command. This is the default command, when none
87  * other has been specified.
88  */
89 function drush_core_help($name = '') {
90   $format = drush_get_option('format', 'table');
91   if ($name) {
92     // helpsingle command builds output when a command is specified.
93     $options = drush_redispatch_get_options();
94     if ($name != 'help') {
95       unset($options['help']);
96     }
97     $return = drush_invoke_process('@self' ,'helpsingle', func_get_args(), $options);
98     drush_backend_set_result($return['object']);
99     return;
100   }
101
102   // For speed, only bootstrap up to DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION.
103   drush_bootstrap_max();
104   drush_get_commands(true);
105   $implemented = drush_get_commands();
106   ksort($implemented);
107   $command_categories = drush_commands_categorize($implemented);
108   if ($format != 'table') {
109     return $command_categories;
110   }
111   else {
112     $visible = drush_help_visible($command_categories);
113
114     // If the user specified --filter w/out a value, then
115     // present a choice list of help categories.
116     if (drush_get_option('filter', FALSE) === TRUE) {
117       $help_categories = array();
118       foreach ($command_categories as $key => $info) {
119         $description = $info['title'];
120         if (array_key_exists('summary', $info)) {
121           $description .= ": " . $info['summary'];
122         }
123         $help_categories[$key] = $description;
124       }
125       $result = drush_choice($help_categories, 'Select a help category:');
126       if (!$result) {
127         return drush_user_abort();
128       }
129       drush_set_option('filter', $result);
130     }
131     // Filter out categories that the user does not want to see
132     $filter_category = drush_get_option('filter');
133     if (!empty($filter_category) && ($filter_category !== TRUE)) {
134       if (!array_key_exists($filter_category, $command_categories)) {
135         return drush_set_error('DRUSH_NO_CATEGORY', dt("The specified command category !filter does not exist.", array('!filter' => $filter_category)));
136       }
137       $command_categories = array($filter_category => $command_categories[$filter_category]);
138     }
139
140     // Make a fake command section to hold the global options, then print it.
141     $global_options_help = drush_global_options_command(TRUE);
142     if (!drush_get_option('filter')) {
143       drush_print_help($global_options_help);
144     }
145     drush_help_listing_print($command_categories);
146     drush_backend_set_result($command_categories);
147     return;
148   }
149 }
150
151 // Uncategorize the list of commands. Hiddens have been removed and
152 // filtering performed.
153 function drush_help_visible($command_categories) {
154   $all = array();
155   foreach ($command_categories as $category => $info) {
156     $all = array_merge($all,  $info['commands']);
157   }
158   return $all;
159 }
160
161 /**
162  * Print CLI table listing all commands.
163  */
164 function drush_help_listing_print($command_categories) {
165   $all_commands = array();
166   foreach ($command_categories as $key => $info) {
167     // Get the commands in this category.
168     $commands = $info['commands'];
169
170     // Build rows for drush_print_table().
171     $rows = array();
172     foreach($commands as $cmd => $command) {
173       $name = $command['aliases'] ? $cmd . ' (' . implode(', ', $command['aliases']) . ')': $cmd;
174       $rows[$cmd] = array('name' => $name, 'description' => $command['description']);
175     }
176     drush_print($info['title'] . ": (" . $key . ")");
177     drush_print_table($rows, FALSE, array('name' => 20));
178   }
179 }
180
181 /**
182  * Build a fake command for the purposes of showing examples and options.
183  */
184 function drush_global_options_command($brief = FALSE) {
185   $global_options_help = array(
186     'description' => 'Execute a drush command. Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.',
187     'sections' => array(
188       'options' => 'Global options (see `drush topic core-global-options` for the full list)',
189     ),
190     'options' => drush_get_global_options($brief),
191     'examples' => array(
192       'drush dl cck zen' => 'Download CCK module and Zen theme.',
193       'drush --uri=http://example.com status' => 'Show status command for the example.com multi-site.',
194     ),
195     '#brief' => TRUE,
196   );
197   $global_options_help += drush_command_defaults('global-options', 'global_options', __FILE__);
198   drush_command_invoke_all_ref('drush_help_alter', $global_options_help);
199   ksort($global_options_help['options']);
200
201   return $global_options_help;
202 }