function drush_core_cli

3.x core.drush.inc drush_core_cli()
4.x core.drush.inc drush_core_cli()

File

commands/core/core.drush.inc, line 819
Core drush commands.

Code

function drush_core_cli() {
  // Do not allow cli to start recursively, or from backend invoke.
  if (drush_get_option('in-cli', FALSE)) {
    return drush_set_error('DRUSH_CLI_NOT_REENTRANT', dt('Already in drush core-cli; press control-d to exit.'));
  }
  if (drush_get_context('DRUSH_BACKEND') || drush_get_context('DRUSH_AFFIRMATIVE') || drush_get_context('DRUSH_NEGATIVE')) {
    return drush_set_error('DRUSH_CLI_INTERACTIVE_ERROR', dt('Cannot run drush core-cli from non-interactive mode; aborting.'));
  }

  // We set interactive mode if we are about to run a bash subshell.
  // The purpose of doing this is that some options are set differently
  // in --pipe mode.  To see everything with --pipe, use --pipe --verbose.
  $interactive_mode = !drush_get_context('DRUSH_PIPE') || drush_get_context('DRUSH_VERBOSE');

  // Make sure that we call drush the same way that we were called.
  // In --pipe mode, just use 'drush'.
  $drush_command = $interactive_mode ? DRUSH_COMMAND . ' --in-cli' : 'drush';

  $bashrc_data = implode("\n\n", drush_command_invoke_all('cli_bashrc', $drush_command, $interactive_mode));

  // Print our bashrc file and exit in --pipe mode
  if (drush_get_context('DRUSH_PIPE')) {
    drush_print_pipe($bashrc_data);
    return TRUE;
  }

  // If there were any errors, then exit.
  if (drush_get_error()) {
    return FALSE;
  }

  drush_print("Entering the drush cli.  Use CONTROL-D to exit.");
  drush_print("Type 'help' for help.");

  // Save out bashrc in a temporary file and launch bash.
  // control-d to exit.  The temp file will be deleted after
  // we exit.
  $bashrc = drush_save_data_to_temp_file($bashrc_data);
  return drush_op_system('bash --rcfile ' . $bashrc . ' > `tty`');
}