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_core_topic_complete A command argument complete 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. $topics = drush_get_topics();
  51. if (isset($topic_name)) {
  52. foreach (drush_get_topics() as $key => $topic) {
  53. if (strstr($key, $topic_name) === FALSE) {
  54. unset($topics[$key]);
  55. }
  56. }
  57. }
  58. if (empty($topics)) {
  59. return drush_set_error('DRUSH_NO_SUCH_TOPIC', dt("No topics on !topic found.", array('!topic' => $topic_name)));
  60. }
  61. if (count($topics) > 1) {
  62. // Show choice list.
  63. foreach ($topics as $key => $topic) {
  64. $choices[$key] = $topic['description'];
  65. }
  66. natcasesort($choices);
  67. if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)', array(5))) {
  68. return;
  69. }
  70. }
  71. else {
  72. $topic_name = array_pop(array_keys($topics));
  73. }
  74. return drush_dispatch($commands[$topic_name]);
  75. }
  76. /**
  77. * A command argument complete callback.
  78. *
  79. * @return
  80. * Available topic keys.
  81. */
  82. function topic_core_topic_complete() {
  83. return array('values' => array_keys(drush_get_topics()));
  84. }
  85. /**
  86. * Retrieve all defined topics
  87. */
  88. function drush_get_topics() {
  89. $commands = drush_get_commands();
  90. foreach ($commands as $key => $command) {
  91. if (!empty($command['topic']) && empty($command['is_alias'])) {
  92. $topics[$key] = $command;
  93. }
  94. }
  95. return $topics;
  96. }