docs.drush.inc

  1. 8.0.x commands/core/docs.drush.inc
  2. 6.x commands/core/docs.drush.inc
  3. 7.x commands/core/docs.drush.inc
  4. 4.x commands/core/docs.drush.inc
  5. 5.x commands/core/docs.drush.inc
  6. master commands/core/docs.drush.inc

Documentation commands providing various topics.

Functions

Namesort descending Description
docs_drush_command Implementation of hook_drush_command().
docs_drush_help Implementation of hook_drush_help().
drush_docs_errorcodes docs-errorcodes command. Print a list of all error codes that can be found.
_drush_docs_find_set_error_calls Search through a php source file looking for calls to the function drush_set_error. If found, and if the first parameter is an uppercase alphanumeric identifier, then record the error code and the error message in our table.

File

commands/core/docs.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Documentation commands providing various topics.
  5. */
  6. /**
  7. * Implementation of hook_drush_help().
  8. */
  9. function docs_drush_help($section) {
  10. switch ($section) {
  11. case 'meta:docs:title':
  12. return dt('Documentation commands');
  13. case 'meta:docs:summary':
  14. return dt('Show information on various drush topics.');
  15. }
  16. }
  17. /**
  18. * Implementation of hook_drush_command().
  19. *
  20. * @return
  21. * An associative array describing your command(s).
  22. */
  23. function docs_drush_command() {
  24. $docs_dir = drush_get_context('DOC_PREFIX', DRUSH_BASE_PATH);
  25. //
  26. // Topic commands.
  27. // Any commandfile may add topics.
  28. // Set 'topic' => TRUE to indicate the command is a topic (REQUIRED)
  29. // Begin the topic name with the name of the commandfile (just like
  30. // any other command).
  31. //
  32. $items['docs-readme'] = array(
  33. 'description' => 'README.md',
  34. 'hidden' => TRUE,
  35. 'topic' => TRUE,
  36. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  37. 'callback' => 'drush_print_file',
  38. 'callback arguments' => array($docs_dir . '/README.md'),
  39. );
  40. $items['docs-bisect'] = array(
  41. 'description' => 'git bisect and Drush may be used together to find the commit an error was introduced in.',
  42. 'hidden' => TRUE,
  43. 'topic' => TRUE,
  44. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  45. 'callback' => 'drush_print_file',
  46. 'callback arguments' => array($docs_dir . '/examples/git-bisect.example.sh'),
  47. );
  48. $items['docs-bashrc'] = array(
  49. 'description' => 'Bashrc customization examples for Drush.',
  50. 'hidden' => TRUE,
  51. 'topic' => TRUE,
  52. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  53. 'callback' => 'drush_print_file',
  54. 'callback arguments' => array($docs_dir . '/examples/example.bashrc'),
  55. );
  56. $items['docs-configuration'] = array(
  57. 'description' => 'Configuration overview with examples from example.drushrc.php.',
  58. 'hidden' => TRUE,
  59. 'topic' => TRUE,
  60. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  61. 'callback' => 'drush_print_file',
  62. 'callback arguments' => array($docs_dir . '/examples/example.drushrc.php'),
  63. );
  64. $items['docs-config-exporting'] = array(
  65. 'description' => 'Drupal configuration export instructions, including customizing configuration by environment.',
  66. 'hidden' => TRUE,
  67. 'topic' => TRUE,
  68. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  69. 'callback' => 'drush_print_file',
  70. 'callback arguments' => array($docs_dir . '/docs/config-exporting.md'),
  71. );
  72. $items['docs-aliases'] = array(
  73. 'description' => 'Site aliases overview on creating your own aliases for commonly used Drupal sites with examples from example.aliases.drushrc.php.',
  74. 'hidden' => TRUE,
  75. 'topic' => TRUE,
  76. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  77. 'callback' => 'drush_print_file',
  78. 'callback arguments' => array($docs_dir . '/examples/example.aliases.drushrc.php'),
  79. );
  80. $items['docs-ini-files'] = array(
  81. 'description' => 'php.ini or drush.ini configuration to set PHP values for use with Drush.',
  82. 'hidden' => TRUE,
  83. 'topic' => TRUE,
  84. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  85. 'callback' => 'drush_print_file',
  86. 'callback arguments' => array($docs_dir . '/examples/example.drush.ini'),
  87. );
  88. $items['docs-bastion'] = array(
  89. 'description' => 'Bastion server configuration: remotely operate on a Drupal sites behind a firewall.',
  90. 'hidden' => TRUE,
  91. 'topic' => TRUE,
  92. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  93. 'callback' => 'drush_print_file',
  94. 'callback arguments' => array($docs_dir . '/docs/bastion.md'),
  95. );
  96. $items['docs-bootstrap'] = array(
  97. 'description' => 'Bootstrap explanation: how Drush starts up and prepares the Drupal environment for use with the command.',
  98. 'hidden' => TRUE,
  99. 'topic' => TRUE,
  100. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  101. 'callback' => 'drush_print_file',
  102. 'callback arguments' => array($docs_dir . '/docs/bootstrap.md'),
  103. );
  104. $items['docs-cron'] = array(
  105. 'description' => 'Crontab instructions for running your Drupal cron tasks via `drush cron`.',
  106. 'hidden' => TRUE,
  107. 'topic' => TRUE,
  108. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  109. 'callback' => 'drush_print_file',
  110. 'callback arguments' => array($docs_dir . '/docs/cron.md'),
  111. );
  112. $items['docs-scripts'] = array(
  113. 'description' => 'Shell script overview on writing simple sequences of Drush statements.',
  114. 'hidden' => TRUE,
  115. 'topic' => TRUE,
  116. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  117. 'callback' => 'drush_print_file',
  118. 'callback arguments' => array($docs_dir . '/docs/shellscripts.md'),
  119. );
  120. $items['docs-shell-aliases'] = array(
  121. 'description' => 'Shell alias overview on creating your own aliases for commonly used Drush commands.',
  122. 'hidden' => TRUE,
  123. 'topic' => TRUE,
  124. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  125. 'callback' => 'drush_print_file',
  126. 'callback arguments' => array($docs_dir . '/docs/shellaliases.md'),
  127. );
  128. $items['docs-commands'] = array(
  129. 'description' => 'Drush command instructions on creating your own Drush commands.',
  130. 'hidden' => TRUE,
  131. 'topic' => TRUE,
  132. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  133. 'callback' => 'drush_print_file',
  134. 'callback arguments' => array($docs_dir . '/docs/commands.md'),
  135. );
  136. $items['docs-errorcodes'] = array(
  137. 'description' => 'Error code list containing all identifiers used with drush_set_error.',
  138. 'hidden' => TRUE,
  139. 'topic' => TRUE,
  140. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  141. );
  142. $items['docs-api'] = array(
  143. 'description' => 'Drush API',
  144. 'hidden' => TRUE,
  145. 'topic' => TRUE,
  146. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  147. 'callback' => 'drush_print_file',
  148. 'callback arguments' => array($docs_dir . '/drush.api.php'),
  149. );
  150. $items['docs-context'] = array(
  151. 'description' => 'Contexts overview explaining how Drush manages command line options and configuration file settings.',
  152. 'hidden' => TRUE,
  153. 'topic' => TRUE,
  154. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  155. 'callback' => 'drush_print_file',
  156. 'callback arguments' => array($docs_dir . '/docs/context.md'),
  157. );
  158. $items['docs-examplescript'] = array(
  159. 'description' => 'Example Drush script.',
  160. 'hidden' => TRUE,
  161. 'topic' => TRUE,
  162. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  163. 'callback' => 'drush_print_file',
  164. 'callback arguments' => array($docs_dir . '/examples/helloworld.script'),
  165. );
  166. $items['docs-examplecommand'] = array(
  167. 'description' => 'Example Drush command file.',
  168. 'hidden' => TRUE,
  169. 'topic' => TRUE,
  170. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  171. 'callback' => 'drush_print_file',
  172. 'callback arguments' => array($docs_dir . '/examples/sandwich.drush.inc'),
  173. );
  174. $items['docs-example-sync-extension'] = array(
  175. 'description' => 'Example Drush commandfile that extends sql-sync to enable development modules in the post-sync hook.',
  176. 'hidden' => TRUE,
  177. 'topic' => TRUE,
  178. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  179. 'callback' => 'drush_print_file',
  180. 'callback arguments' => array($docs_dir . '/examples/sync_enable.drush.inc'),
  181. );
  182. $items['docs-example-sync-via-http'] = array(
  183. 'description' => 'Example Drush commandfile that extends sql-sync to allow transfer of the sql dump file via http rather than ssh and rsync.',
  184. 'hidden' => TRUE,
  185. 'topic' => TRUE,
  186. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  187. 'callback' => 'drush_print_file',
  188. 'callback arguments' => array($docs_dir . '/examples/sync_via_http.drush.inc'),
  189. );
  190. $items['docs-policy'] = array(
  191. 'description' => 'Example policy file.',
  192. 'hidden' => TRUE,
  193. 'topic' => TRUE,
  194. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  195. 'callback' => 'drush_print_file',
  196. 'callback arguments' => array($docs_dir . '/examples/policy.drush.inc'),
  197. );
  198. $items['docs-strict-options'] = array(
  199. 'description' => 'Strict option handling, and how commands that use it differ from regular Drush commands.',
  200. 'hidden' => TRUE,
  201. 'topic' => TRUE,
  202. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  203. 'callback' => 'drush_print_file',
  204. 'callback arguments' => array($docs_dir . '/docs/strict-options.md'),
  205. );
  206. return $items;
  207. }
  208. /**
  209. * docs-errorcodes command. Print a list of all error codes
  210. * that can be found.
  211. */
  212. function drush_docs_errorcodes() {
  213. $header = <<<EOD
  214. ==== Drush Error Codes ====
  215. Drush error codes are alphanumeric constants that represent an unrecoverable error condition that may arise during the execution of some command. They are set by the following function:
  216. return drush_set_error('DRUSH_ERROR_CODE', dt('Error message.'));
  217. In general, any drush command that calls drush_set_error is expected to also return FALSE as its function result. The drush_set_error function returns FALSE to make it easy to exit with an error code. Error codes are returned as part of the drush backend invoke process, which is used by drush API functions such as drush_invoke_process. An example of how to test for a specific error code is shown below:
  218. \$result = drush_invoke_process('@self', 'some-command');
  219. if (array_key_exists('DRUSH_ERROR_CODE', \$result['error_log'])) {
  220. // handle ocurrances of DRUSH_ERROR_CODE here
  221. }
  222. Some of the available drush error codes are listed in the table below.
  223. EOD;
  224. // Find all of the files that we will search for error messages.
  225. // Start with all of the commandfiles.
  226. $commandfiles = drush_commandfile_list();
  227. $files = array_flip($commandfiles);
  228. // In addition to the commandfiles, we will also look for files
  229. // that drush will load when executing a command (e.g
  230. // updatecode.pm.inc)
  231. $commands = drush_get_commands();
  232. foreach ($commands as $command_name => $command) {
  233. $files = array_merge($files, drush_command_get_includes($command_name));
  234. }
  235. // We will also search through all of the .inc files in the
  236. // drush includes directory
  237. $drush_include_files = drush_scan_directory(DRUSH_BASE_PATH . '/includes', '/.*\.inc$/', array('.', '..', 'CVS'), 0, FALSE);
  238. foreach ($drush_include_files as $filename => $info) {
  239. $files[$filename] = 'include';
  240. }
  241. // Extract error messages from all command files
  242. $error_list = array();
  243. foreach ($files as $file => $commandfile) {
  244. _drush_docs_find_set_error_calls($error_list, $file, $commandfile);
  245. }
  246. // Order error messages alphabetically by key
  247. ksort($error_list);
  248. // Convert to a table
  249. $data = array();
  250. foreach ($error_list as $error_code => $error_messages) {
  251. $data[] = array($error_code, '-', implode("\n", $error_messages));
  252. }
  253. $tmpfile = drush_tempnam('drush-errorcodes.');
  254. file_put_contents($tmpfile, $header);
  255. $handle = fopen($tmpfile, 'a');
  256. drush_print_table($data, FALSE, array(0 => 35), $handle);
  257. fclose($handle);
  258. drush_print_file($tmpfile);
  259. }
  260. /**
  261. * Search through a php source file looking for calls to
  262. * the function drush_set_error. If found, and if the
  263. * first parameter is an uppercase alphanumeric identifier,
  264. * then record the error code and the error message in our table.
  265. */
  266. function _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname) {
  267. $lines = file($filename);
  268. foreach ($lines as $line) {
  269. $matches = array();
  270. // Find the error code after the drush_set_error call. The error code
  271. // should consist of uppercase letters and underscores only (numbers thrown in just in case)
  272. $match_result = preg_match("/.*drush_set_error[^'\"]['\"]([A-Z0-9_]*)['\"][^,]*,[^'\"]*(['\"])/", $line, $matches);
  273. if ($match_result) {
  274. $error_code = $matches[1];
  275. $quote_char = $matches[2];
  276. $error_message = "";
  277. $message_start = strlen($matches[0]) - 1;
  278. // Regex adapted from http://stackoverflow.com/questions/1824325/regex-expression-for-escaped-quoted-string-wont-work-in-phps-preg-match-allif ($quote_char == '"') {
  279. if ($quote_char == '"') {
  280. $regex = '/"((?:[^\\\]*?(?:\\\")?)*?)"/';
  281. }
  282. else {
  283. $regex = "/'((?:[^\\\]*?(?:\\\')?)*?)'/";
  284. }
  285. $match_result = preg_match($regex, $line, $matches, 0, $message_start);
  286. if ($match_result) {
  287. $error_message = $matches[1];
  288. }
  289. $error_list[$error_code] = array_key_exists($error_code, $error_list) ? array_merge($error_list[$error_code], array($error_message)) : array($error_message);
  290. }
  291. }
  292. }