function drush_topic_core_topic

8.0.x topic.drush.inc drush_topic_core_topic($topic_name = NULL)
6.x topic.drush.inc drush_topic_core_topic($topic_name = NULL)
7.x topic.drush.inc drush_topic_core_topic($topic_name = NULL)
4.x topic.drush.inc drush_topic_core_topic($topic_name = NULL)
5.x topic.drush.inc drush_topic_core_topic($topic_name = NULL)
master topic.drush.inc drush_topic_core_topic($topic_name = NULL)

A command callback.

Show a choice list of available topics and then dispatch to the respective command.

Parameters

string $topic_name: A command name.

File

commands/core/topic.drush.inc, line 54
Topic command and associated hooks.

Code

function drush_topic_core_topic($topic_name = NULL) {
  $commands = drush_get_commands();
  $topics = drush_get_topics();
  if (isset($topic_name)) {
    foreach (drush_get_topics() as $key => $topic) {
      if (strstr($key, $topic_name) === FALSE) {
        unset($topics[$key]);
      }
    }
  }
  if (empty($topics)) {
    return drush_set_error('DRUSH_NO_SUCH_TOPIC', dt("No topics on !topic found.", array('!topic' => $topic_name)));
  }
  if (count($topics) > 1) {
    // Show choice list.
    foreach ($topics as $key => $topic) {
      $choices[$key] = $topic['description'];
    }
    natcasesort($choices);
    if (!$topic_name = drush_choice($choices, dt('Choose a topic'), '!value (!key)', array(5))) {
      return drush_user_abort();
    }
  }
  else {
    $topic_name = array_pop(array_keys($topics));
  }
  return drush_dispatch($commands[$topic_name]);
}