protected function DrushCommand::execute

8.0.x DrushCommand.php protected DrushCommand::execute(InputInterface $input, OutputInterface $output)
master DrushCommand.php protected DrushCommand::execute(InputInterface $input, OutputInterface $output)

File

lib/Drush/Psysh/DrushCommand.php, line 79
Contains \Drush\Psysh\DrushCommand.

Namespace

Drush\Psysh

Class

DrushCommand
Main Drush command.

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $args = $input->getArguments();
  $first = array_shift($args);

  // If the first argument is an alias, assign the next argument as the
  // command.
  if (strpos($first, '@') === 0) {
    $alias = $first;
    $command = array_shift($args);
  }
  // Otherwise, default the alias to '@self' and use the first argument as the
  // command.
  else {
    $alias = '@self';
    $command = $first;
  }

  $options = $input->getOptions();
  // Force the 'backend' option to TRUE.
  $options['backend'] = TRUE;

  $return = drush_invoke_process($alias, $command, array_values($args), $options, ['interactive' TRUE]);

  if ($return['error_status'] > 0) {
    foreach ($return['error_log'] as $error_type => $errors) {
      $output->write($errors);
    }
    // Add a newline after so the shell returns on a new line.
    $output->writeln('');
  }
  else {
    $output->page(drush_backend_get_result());
  }
}