TRUE to indicate the command is a topic (REQUIRED) // Begin the topic name with the name of the commandfile (just like // any other command). // $items['docs-readme'] = array( 'description' => dt('README.txt'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/README.txt'), ); $items['docs-configuration'] = array( 'description' => dt('Drush configuration overview with examples'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/example.drushrc.php'), ); $items['docs-aliases'] = array( 'description' => dt('Site aliases overview with examples'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/example.aliases.drushrc.php'), ); $items['docs-ini-files'] = array( 'description' => dt('Configuring php.ini or drush.ini for use with drush'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/example.drush.ini'), ); $items['docs-bootstrap'] = array( 'description' => dt('Information about the drush bootstrap process.'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/docs/bootstrap.html'), ); $items['docs-scripts'] = array( 'description' => dt('Overview on how to write drush shell scripts.'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/docs/shellscripts.html'), ); $items['docs-commands'] = array( 'description' => dt('Overview on how to write drush commands.'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/docs/commands.html'), ); $items['docs-errorcodes'] = array( 'description' => dt('Summary of drush error codes.'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); $items['docs-api'] = array( 'description' => dt('Drush API'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/docs/drush.api.php'), ); $items['docs-context'] = array( 'description' => dt('Drush contexts'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/docs/context.html'), ); $items['docs-examplescript'] = array( 'description' => dt('Example drush script'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/helloworld.script'), ); $items['docs-examplecommand'] = array( 'description' => dt('Example drush command file.'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/sandwich.drush.inc'), ); $items['docs-policy'] = array( 'description' => dt('Example policy file'), 'hidden' => TRUE, 'topic' => TRUE, 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'callback' => 'drush_print_file', 'callback arguments' => array(DRUSH_BASE_PATH . '/examples/policy.drush.inc'), ); return $items; } /** * docs-error-codes command. Print a list of all error codes * that can be found. */ function drush_docs_errorcodes() { $header = << $command) { $files = array_merge($files, drush_command_get_includes($command_name)); } // We will also search through all of the .inc files in the // drush includes directory $drush_include_files = drush_scan_directory(DRUSH_BASE_PATH . '/includes', '/.*\.inc$/', array('.', '..', 'CVS'), 0, FALSE); foreach ($drush_include_files as $filename => $info) { $files[$filename] = 'include'; } // Extract error messages from all command files $error_list = array(); foreach ($files as $file => $commandfile) { _drush_docs_find_set_error_calls($error_list, $file, $commandfile); } // Order error messages alphabetically by key ksort($error_list); // Convert to a table $data = array(); foreach ($error_list as $error_code => $error_messages) { $data[] = array($error_code, '-', implode("\n", $error_messages)); } $tmpfile = drush_tempnam('drush-errorcodes.'); file_put_contents($tmpfile, $header); drush_print_table($data, FALSE, array(0 => 35), $tmpfile); drush_print_file($tmpfile); } /** * 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. */ function _drush_docs_find_set_error_calls(&$error_list, $filename, $shortname) { $lines = file($filename); foreach ($lines as $line) { $matches = array(); // Find the error code after the drush_set_error call. The error code // should consist of uppercase letters and underscores only (numbers thrown in just in case) $match_result = preg_match("/.*drush_set_error[^'\"]['\"]([A-Z0-9_]*)['\"][^,]*,[^'\"]*(['\"])/", $line, $matches); if ($match_result) { $error_code = $matches[1]; $quote_char = $matches[2]; $error_message = ""; $message_start = strlen($matches[0]) - 1; // Regex adapted from http://stackoverflow.com/questions/1824325/regex-expression-for-escaped-quoted-string-wont-work-in-phps-preg-match-allif ($quote_char == '"') { if ($quote_char == '"') { $regex = '/"((?:[^\\\]*?(?:\\\")?)*?)"/'; } else { $regex = "/'((?:[^\\\]*?(?:\\\')?)*?)'/"; } $match_result = preg_match($regex, $line, $matches, 0, $message_start); if ($match_result) { $error_message = $matches[1]; } $error_list[$error_code] = array_key_exists($error_code, $error_list) ? array_merge($error_list[$error_code], array($error_message)) : array($error_message); } } }