topic.drush.inc

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

Topic command and associated hooks.

Functions

Namesort descending Description
drush_get_topics Retrieve all defined topics
drush_topic_core_topic A command callback.
topic_drush_command Implementation of hook_drush_command().
topic_drush_help_alter Implement hook_drush_help_alter(). Show 'Topics' section on help detail.

File

commands/core/topic.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Topic command and associated hooks.
  5. */
  6. /**
  7. * Implementation of hook_drush_command().
  8. *
  9. * @return
  10. * An associative array describing your command(s).
  11. */
  12. function topic_drush_command() {
  13. $items['core-topic'] = array(
  14. 'description' => 'Read detailed documentation on a given topic.',
  15. 'arguments' => array(
  16. 'topic name' => 'The name of the topic you wish to view. If omitted, list all topic descriptions (and names in parenthesis).',
  17. ),
  18. 'examples' => array(
  19. 'drush topic' => 'Show all available topics.',
  20. 'drush topic docs-context' => 'Show documentation for the drush context API',
  21. 'drush docs-context' => 'Show documentation for the drush context API',
  22. ),
  23. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
  24. 'aliases' => array('topic'),
  25. 'topics' => array('docs-readme'),
  26. );
  27. return $items;
  28. }
  29. /**
  30. * Implement hook_drush_help_alter(). Show 'Topics' section on help detail.
  31. */
  32. function topic_drush_help_alter($command) {
  33. $implemented = drush_get_commands();
  34. foreach ($command['topics'] as $topic_name) {
  35. // We have a related topic. Inject into the $command so the topic displays.
  36. $command['sections']['topic_section'] = 'Topics';
  37. $command['topic_section'][$topic_name] = $implemented[$topic_name]['description'];
  38. }
  39. }
  40. /**
  41. * A command callback.
  42. *
  43. * Show a choice list of available topics and then dispatch to the respective command.
  44. *
  45. * @param string $topic_name
  46. * A command name.
  47. */
  48. function drush_topic_core_topic($topic_name = NULL) {
  49. $commands = drush_get_commands();
  50. if (is_null($topic_name)) {
  51. // Show choice list.
  52. foreach (drush_get_topics() as $key => $topic) {
  53. $choices[$key] = $topic['description'];
  54. }
  55. natcasesort($choices);
  56. if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)')) {
  57. return;
  58. }
  59. }
  60. // If the topic name is not found, check for
  61. // "docs-$topic_name". This allows users to be
  62. // just a bit lazy when selecting core topics by name.
  63. if (!isset($commands[$topic_name]) && isset($commands["docs-$topic_name"])) {
  64. $topic_name = "docs-$topic_name";
  65. }
  66. return drush_dispatch($commands[$topic_name]);
  67. }
  68. /**
  69. * Retrieve all defined topics
  70. */
  71. function drush_get_topics() {
  72. $commands = drush_get_commands();
  73. foreach ($commands as $key => $command) {
  74. if (!empty($command['topic']) && empty($command['is_alias'])) {
  75. $topics[$key] = $command;
  76. }
  77. }
  78. return $topics;
  79. }