function drush_cli_core_cli

8.0.x cli.drush.inc drush_cli_core_cli()
7.x cli.drush.inc drush_cli_core_cli()
master cli.drush.inc drush_cli_core_cli()

Command callback.

File

commands/core/cli.drush.inc, line 37

Code

function drush_cli_core_cli() {
  $drupal_major_version = drush_drupal_major_version();
  $configuration = new \Psy\Configuration();

  // Set the Drush specific history file path.
  $configuration->setHistoryFile(drush_history_path_cli());

  $shell = new Shell($configuration);

  if ($drupal_major_version >= 8) {
    // Register the assertion handler so exceptions are thrown instead of errors
    // being triggered. This plays nicer with PsySH.
    Handle::register();
    $shell->setScopeVariables(['container' \Drupal::getContainer()]);

    // Add Drupal 8 specific casters to the shell configuration.
    $configuration->addCasters(_drush_core_cli_get_casters());
  }

  // Add Drush commands to the shell.
  $commands =[new DrushHelpCommand()];

  foreach (drush_commands_categorize(_drush_core_cli_get_commands()) as $category_data) {
    $category_title = (string) $category_data['title'];
    foreach ($category_data['commands'] as $command_config) {
      $command = new DrushCommand($command_config);
      // Set the category label on each.
      $command->setCategory($category_title);
      $commands[] = $command;
    }
  }

  $shell->addCommands($commands);

  // PsySH will never return control to us, but our shutdown handler will still
  // run after the user presses ^D.  Mark this command as completed to avoid a
  // spurious error message.
  drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);

  // Run the terminate event before the shell is run. Otherwise, if the shell
  // is forking processes (the default), any child processes will close the
  // database connection when they are killed. So when we return back to the
  // parent process after, there is no connection. This will be called after the
  // command in preflight still, but the subscriber instances are already
  // created from before. Call terminate() regardless, this is a no-op for all
  // DrupalBoot classes except DrupalBoot8.
  if ($bootstrap = \Drush::bootstrap()) {
    $bootstrap->terminate();
  }

  // To fix the above problem in Drupal 7, the connection can be closed manually.
  // This will make sure a new connection is created again in child loops. So
  // any shutdown functions will still run ok after the shell has exited.
  if ($drupal_major_version == 7) {
    Database::closeConnection();
  }

  $shell->run();
}