'version_callback', // a short description of your command 'description' => "Drush version command. Print CVS tags of .drush.inc files.", ); // more commands here ... return $items; } /** * Implementation of hook_drush_help(). * * This function is called whenever a drush user calls * 'drush help ' * * @param * A string with the help section (prepend with 'drush:') * * @return * A string with the help text for your command. */ function version_drush_help($section) { switch ($section) { case 'drush:version': return dt("Drush version command. Print CVS tags of .drush.inc files. Requires drush to be checked out from CVS."); } } /** * Example drush command callback. * * This is where the action takes place. * * In this function, all of Drupals API is (usually) available, including * any functions you have added in your own modules/themes. * * To print something to the terminal window, use drush_print(). * */ function version_callback() { $commands = func_get_args(); // Using the Drupal API function 'format_interval()' // and Drush API function 'drush_print' $list = drush_commandfile_list(); $table[0]['name']="Name"; $table[0]['version']="Version"; $table[0]['path']="File Path"; foreach($list as $command_name => $command_file) { $table[$command_name]['name'] = $command_name; $table[$command_name]['version'] = _drush_version_get_version($command_file); $table[$command_name]['path'] = $command_file; } drush_print_table($table, 0, true); } function _drush_version_get_version($command_file) { // $path includes the file name. seperate them out. $file = basename($command_file); $dir = dirname($command_file); $working_directory = getcwd(); chdir($dir); drush_shell_exec("cvs status $file"); $output = drush_shell_exec_output(); $version = "Unknown."; foreach($output as $line) { if(strstr($line, "Sticky Tag:")) { $possible_line = trim(str_replace("Sticky Tag:", "", $line)); $possible = trim(strtok($possible_line, "(")); if ($possible) $version = $possible; } } chdir($working_directory); return $version; }