Skip to content

Commit

Permalink
Fixes #1589: @executeInDrupalVm not respected during invokeCommand. (#…
Browse files Browse the repository at this point in the history
…1595)

* Fixes #1589: @executeInDrupalVm not respected during invokeCommand.

* Making invokeCommand() trigger Command Events.
  • Loading branch information
grasmash authored Jun 5, 2017
1 parent 5efdffa commit 62e3f7e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/Robo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Acquia\Blt\Robo;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application as ConsoleApplication;

/**
* Class Application
* @package Acquia\Blt\Robo
*/
class Application extends ConsoleApplication {

/**
* @param \Symfony\Component\Console\Command\Command $command
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*
* @return int
* The exit code.
*/
public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
return $this->doRunCommand($command, $input, $output);
}

}
4 changes: 2 additions & 2 deletions src/Robo/Blt.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Robo\Config\Config;
use Robo\Robo;
use Robo\Runner as RoboRunner;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -224,7 +223,8 @@ public function configureContainer($container) {
* The exiting status code of the application
*/
public function run(InputInterface $input, OutputInterface $output) {
$status_code = $this->runner->run($input, $output, NULL, $this->commands);
$application = $this->getContainer()->get('application');
$status_code = $this->runner->run($input, $output, $application, $this->commands);

return $status_code;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Robo/BltTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ protected function invokeCommand($command_name, array $args = []) {
return 0;
}

/** @var \Robo\Application $application */
/** @var \Acquia\Blt\Robo\Application $application */
$application = $this->getContainer()->get('application');
$command = $application->find($command_name);

$input = new ArrayInput($args);
$prefix = str_repeat(">", $this->invokeDepth);
$this->output->writeln("<comment>$prefix $command_name</comment>");
$returnCode = $command->run($input, $this->output());
$return_code = $application->runCommand($command, $input, $this->output());
$this->invokeDepth--;

return $returnCode;
return $return_code;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Robo/Hooks/CommandEventHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function executeInDrupalVm(ConsoleCommandEvent $event) {
if (method_exists($command, 'getAnnotationData')) {
/* @var \Consolidation\AnnotatedCommand\AnnotationData */
$annotation_data = $event->getCommand()->getAnnotationData();
$this->warnIfDrupalVmNotRunning();
if ($annotation_data->has('executeInDrupalVm') && $this->shouldExecuteInDrupalVm()) {
$event->disableCommand();
$args = $this->getCliArgs();
Expand Down Expand Up @@ -95,4 +96,13 @@ protected function shouldExecuteInDrupalVm() {
&& !$this->getInspector()->isVmCli();
}

/**
* Emits a warning if Drupal VM is initialized but not running.
*/
protected function warnIfDrupalVmNotRunning() {
if ($this->getInspector()->isDrupalVmLocallyInitialized() && !$this->getInspector()->isDrupalVmBooted()) {
$this->logger->warning("Drupal VM is locally initialized, but it not running.");
}
}

}

0 comments on commit 62e3f7e

Please sign in to comment.