Skip to content

Commit

Permalink
[exec] Show command info. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Dec 30, 2016
1 parent 221ad3b commit 99fc369
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
class: Drupal\Console\Core\Utils\FileQueue
console.shell_process:
class: Drupal\Console\Core\Utils\ShellProcess
arguments: ['@app.root']
arguments: ['@app.root', '@console.translator_manager']
console.string_converter:
class: Drupal\Console\Core\Utils\StringConverter
console.chain_discovery:
Expand Down
18 changes: 18 additions & 0 deletions src/Command/Exec/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\ExecutableFinder;
use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Core\Utils\ShellProcess;
use Drupal\Console\Core\Style\DrupalStyle;
Expand Down Expand Up @@ -76,6 +77,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$name = $bin;
if ($index = stripos($name, " ")) {
$name = substr($name, 0, $index);
}

$finder = new ExecutableFinder();
if (!$finder->find($name)) {
$io->error(
sprintf(
$this->trans('commands.exec.messages.binary-not-found'),
$name
)
);

return 1;
}

if (!$this->shellProcess->exec($bin, $workingDirectory)) {
$io->error(
sprintf(
Expand Down
24 changes: 22 additions & 2 deletions src/Utils/ShellProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ShellProcess
*/
protected $appRoot;

/**
* @var TranslatorManager
*/
protected $translator;

/**
* @var ShellProcess
*/
Expand All @@ -30,11 +35,13 @@ class ShellProcess

/**
* Process constructor.
* @param string $appRoot
* @param string $appRoot
* @param TranslatorManager $translator
*/
public function __construct($appRoot)
public function __construct($appRoot, $translator)
{
$this->appRoot = $appRoot;
$this->translator = $translator;

$output = new ConsoleOutput();
$input = new ArrayInput([]);
Expand All @@ -54,6 +61,19 @@ public function exec($command, $workingDirectory=null)
if (!$workingDirectory || $workingDirectory==='') {
$workingDirectory = $this->appRoot;
}

$this->io->newLine();
$this->io->comment(
$this->translator->trans('commands.exec.messages.working-directory') .': ',
false
);
$this->io->writeln($workingDirectory);
$this->io->comment(
$this->translator->trans('commands.exec.messages.executing-command') .': ',
false
);
$this->io->writeln($command);

$this->process = new Process($command);
$this->process->setWorkingDirectory($workingDirectory);
$this->process->enableOutput();
Expand Down
10 changes: 5 additions & 5 deletions src/Utils/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Drupal\Console\Core\Utils;

use MongoDB\Driver\Manager;
use Drupal\Console\Core\Utils\TranslatorManager;;

/**
* Class TwigRenderer
Expand All @@ -16,7 +16,7 @@
class TwigRenderer
{
/**
* @var Manager
* @var TranslatorManager
*/
protected $translator;

Expand All @@ -37,11 +37,11 @@ class TwigRenderer

/**
* TwigRenderer constructor.
* @param Manager $translator
* @param StringConverter $stringConverter
* @param TranslatorManager $translator
* @param StringConverter $stringConverter
*/
public function __construct(
Manager $translator,
TranslatorManager $translator,
StringConverter $stringConverter
) {
$this->translator = $translator;
Expand Down

0 comments on commit 99fc369

Please sign in to comment.