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_NONE,
  24. 'remote-tty' => TRUE,
  25. 'aliases' => array('topic'),
  26. 'topics' => array('docs-readme'),
  27. );
  28. return $items;
  29. }
  30. /**
  31. * Implement hook_drush_help_alter(). Show 'Topics' section on help detail.
  32. */
  33. function topic_drush_help_alter(&$command) {
  34. $implemented = drush_get_commands();
  35. foreach ($command['topics'] as $topic_name) {
  36. // We have a related topic. Inject into the $command so the topic displays.
  37. $command['sections']['topic_section'] = 'Topics';
  38. $command['topic_section'][$topic_name] = $implemented[$topic_name]['description'];
  39. }
  40. }
  41. /**
  42. * A command callback.
  43. *
  44. * Show a choice list of available topics and then dispatch to the respective command.
  45. *
  46. * @param string $topic_name
  47. * A command name.
  48. */
  49. function drush_topic_core_topic($topic_name = NULL) {
  50. $commands = drush_get_commands();
  51. $topics = drush_get_topics();
  52. if (isset($topic_name)) {
  53. foreach (drush_get_topics() as $key => $topic) {
  54. if (strstr($key, $topic_name) === FALSE) {
  55. unset($topics[$key]);
  56. }
  57. }
  58. }
  59. if (empty($topics)) {
  60. return drush_set_error('DRUSH_NO_SUCH_TOPIC', dt("No topics on !topic found.", array('!topic' => $topic_name)));
  61. }
  62. if (count($topics) > 1) {
  63. // Show choice list.
  64. foreach ($topics as $key => $topic) {
  65. $choices[$key] = $topic['description'];
  66. }
  67. natcasesort($choices);
  68. if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)', array(5))) {
  69. return drush_user_abort();
  70. }
  71. }
  72. else {
  73. $topic_name = array_pop(array_keys($topics));
  74. }
  75. return drush_dispatch($commands[$topic_name]);
  76. }
  77. /**
  78. * A command argument complete callback.
  79. *
  80. * @return
  81. * Available topic keys.
  82. */
  83. function topic_core_topic_complete() {
  84. return array('values' => array_keys(drush_get_topics()));
  85. }
  86. /**
  87. * Retrieve all defined topics
  88. */
  89. function drush_get_topics() {
  90. $commands = drush_get_commands();
  91. foreach ($commands as $key => $command) {
  92. if (!empty($command['topic']) && empty($command['is_alias'])) {
  93. $topics[$key] = $command;
  94. }
  95. }
  96. return $topics;
  97. }