Index: drush.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.php,v retrieving revision 1.68 diff -u -d -p -r1.68 drush.php --- drush.php 4 Jun 2009 19:48:55 -0000 1.68 +++ drush.php 24 Jun 2009 08:24:23 -0000 @@ -156,12 +156,7 @@ function drush_shutdown() { elseif (drush_get_context('DRUSH_QUIET')) { ob_end_clean(); } - - // If we are in pipe mode, emit the compact representation of the command, if available. - if (drush_get_context('DRUSH_PIPE')) { - drush_pipe_output(); - } - + exit((drush_get_error()) ? DRUSH_FRAMEWORK_ERROR : DRUSH_SUCCESS); } Index: commands/core/core.drush.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v retrieving revision 1.30 diff -u -d -p -r1.30 core.drush.inc --- commands/core/core.drush.inc 2 Jun 2009 23:48:31 -0000 1.30 +++ commands/core/core.drush.inc 24 Jun 2009 08:24:24 -0000 @@ -29,7 +29,6 @@ function core_drush_command() { 'examples' => array( 'drush dl cck zen' => 'Download CCK module and Zen theme.', 'drush --uri=http://example.com status' => 'Show status command for the example.com multi-site.', - 'drush help --pipe' => 'A space delimited list of commands', ), ); $items['cron'] = array( @@ -100,6 +99,9 @@ function core_drush_command() { 'code' => 'PHP code', ), ); + $items['complete'] = array( + 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap. + ); return $items; } @@ -155,7 +157,6 @@ function drush_core_help() { foreach($commands as $key => $command) { if (!array_key_exists($key, $printed_rows)) { $rows[$key] = array($key, $commands[$key]['description']); - $pipe[] = "\"$key\""; } } drush_print_table($rows, FALSE, array(0 => 20)); @@ -165,9 +166,7 @@ function drush_core_help() { break; } } - - // Space delimited list for use by other scripts. Set the --pipe option. - drush_print_pipe(implode(' ', $pipe)); + return; } else { @@ -439,3 +438,87 @@ function drush_core_watchdog_delete($typ function drush_core_eval($command) { eval($command . ';'); } + +function drush_core_complete() { + // Bootstrap to the highest level possible (up to the database level). + drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_DATABASE); + + + // Set up arguments as if we were running the command, and attempt to parse. + $args = drush_get_context('argv'); + // TODO: This needs work. + // For some reason we get duplicate drush/drush.php arguments in some cases, + // we also need to remove the "complete" command (running now). + $args = preg_grep("/(drush|drush.php|complete)/", $args, PREG_GREP_INVERT); + // We also get an empty argument on the end when we autocomplete on just 'drush '. + $last_word = end($args); + if (empty($last_word)) { + array_pop($args); + } + // Add the drush command back in, since we removed it above. + array_unshift($args, 'drush'); + // Reindex the array. + $args = array_values($args); + drush_set_context('argv', $args); + drush_set_command(NULL); + drush_parse_args(); + drush_parse_command(); + +// Argument debugging code +// foreach ($args as $n => $arg) { +// $completions[] = $n.'-'.$arg; +// } + + $command = drush_get_command(); + $complete = drush_command_invoke_all('drush_complete'); + $completions = array(); + + // Add in any command specific options. + if ($command && $command['command'] !== 'help') { + $complete['options'] = array_merge($complete['options'], array_keys($command['options'])); + } + // Remove any options that have been already specified. + foreach (array_keys(drush_get_merged_options()) as $option) { + unset($complete['options'][array_search('--' . $option, $complete['options'])]); + } + + // Complete options (starting with a hypnen) first. + $last_word = end($args); + if ($last_word[0] == '-') { + $completions = preg_grep("/^$last_word/", $complete['options']); + } + else if ($command) { + // We do have a valid command already, so we try matching command arguments. + if (isset($complete[$command['command']])) { + while (!empty($args) && empty($completions)) { + $candidate = implode(' ', $args); + $completions = preg_grep("/^$candidate/", $complete[$command['command']]); + array_shift($args); + } + if (empty($completions)) { + $completions = $complete[$command['command']] + $complete['options']; + } + } + } + else { + // We don't have a valid command, so we complete available commands trying + // the longest match first. + while (!empty($args) && empty($completions)) { + $candidate = implode(' ', $args); + $completions = preg_grep("/^$candidate/", $complete['commands']); + array_shift($args); + } + } + // The default, if we haven't yet found any context sensitive completions is + // to return commands and options. + if (empty($completions)) { + $completions = array_merge($complete['commands'], $complete['options']); + } + drush_print(implode("\n", $completions)); +} + +function core_drush_complete() { + // TODO: Store this in a better structured format upstream + preg_match_all('/--[a-z-]*/', implode(' ', array_keys(drush_get_option_help())), $matches); + return array('commands' => array_keys(drush_get_commands()), 'options' => $matches[0]); +} \ No newline at end of file Index: commands/pm/pm.drush.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/pm/pm.drush.inc,v retrieving revision 1.41 diff -u -d -p -r1.41 pm.drush.inc --- commands/pm/pm.drush.inc 18 Jun 2009 01:39:16 -0000 1.41 +++ commands/pm/pm.drush.inc 24 Jun 2009 08:24:24 -0000 @@ -101,9 +101,6 @@ function pm_drush_command() { 'description' => 'Show module enabled/disabled status', 'callback' => 'pm_module_manage', 'callback arguments' => array(array(), FALSE), - 'options' => array( - '--pipe' => 'Returns a space delimited list of enabled modules.', - ), ); $items['refresh'] = array( 'description' => 'Refresh update status information', @@ -308,9 +305,6 @@ function pm_module_status($enabled, $mod $rows[] = array($info['name'] . ' (' . $module_name . ')', $enabled, truncate_utf8($info['description'], 60, FALSE, TRUE)); } drush_print_table($rows, TRUE); - - // Space delimited list for use by other scripts. Set the --pipe option. - drush_print_pipe(implode(' ', $pipe)); } /** @@ -828,3 +822,21 @@ function drush_pm_dl() { unset($package, $error, $release, $types); } } + +function pm_drush_complete() { + $complete = array(); + if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_DATABASE) { + $result = db_query('SELECT name, status FROM {system} WHERE type = "module"'); + while ($module = db_fetch_object($result)) { + if ($module->status == TRUE) { + $complete['disable'][] = $module->name; + } + else { + $complete['enable'][] = $module->name; + } + } + + + } + return $complete; +} \ No newline at end of file Index: includes/drush.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v retrieving revision 1.41 diff -u -d -p -r1.41 drush.inc --- includes/drush.inc 27 May 2009 00:47:38 -0000 1.41 +++ includes/drush.inc 24 Jun 2009 08:24:24 -0000 @@ -298,7 +298,6 @@ function drush_get_option_help() { $options['-c, --config'] = dt("Specify a config file to use. See example.drushrc.php"); $options['-u, --user'] = dt("Specify a user to login with. May be a name or a number."); $options['-b, --backend'] = dt("Hide all output and return structured data (internal use only)."); - $options['-p, --pipe'] = dt("Emit a compact representation of the command for scripting."); return $options; } @@ -440,16 +439,6 @@ function drush_print($message = '', $ind } /** - * Stores a message which is printed during drush_shutdown() if in compact mode. - * @param $message - * The message to print. - */ -function drush_print_pipe($message = '') { - $buffer = &drush_get_context('DRUSH_PIPE_BUFFER' , ''); - $buffer .= $message; -} - -/** * Prints an array or string. * @param $array * The array to print. @@ -663,14 +652,6 @@ function dlm($object) { drush_log($contents); } -/* - * Display the pipe output for the current request. - */ -function drush_pipe_output() { - $pipe = drush_get_context('DRUSH_PIPE_BUFFER'); - drush_print_r($pipe); -} - /** * Display the log message * Index: includes/environment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v retrieving revision 1.37 diff -u -d -p -r1.37 environment.inc --- includes/environment.inc 24 Jun 2009 00:00:23 -0000 1.37 +++ includes/environment.inc 24 Jun 2009 08:24:24 -0000 @@ -242,9 +242,12 @@ function drush_bootstrap_validate($phase /** * Bootstrap to the highest level possible, without triggering any errors. */ -function drush_bootstrap_max() { +function drush_bootstrap_max($max = NULL) { $phases = _drush_bootstrap_phases(); $phase_index = DRUSH_BOOTSTRAP_DRUSH; + if (isset($max)) { + $phases = array_slice($phases, 0, $max+1); + } // Try to bootstrap to the maximum possible level, without generating errors foreach ($phases as $phase_index) { @@ -408,11 +411,8 @@ function _drush_bootstrap_drush() { drush_set_context('stdin', $stdin_options); } } - - // Pipe implies quiet. - $quiet = drush_set_context('DRUSH_QUIET', drush_get_option(array('q', 'quiet', 'p', 'pipe'))); - - drush_set_context('DRUSH_PIPE', drush_get_option(array('p', 'pipe'))); + + $quiet = drush_set_context('DRUSH_QUIET', drush_get_option(array('q', 'quiet'))); // When running in backend mode, all output is buffered, and returned // as a property of a JSON encoded associative array.