Skip to content

Commit

Permalink
[exec] Add working-directory option. (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas committed Dec 21, 2016
1 parent b0b7377 commit 24940dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Command/Exec/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Utils\ShellProcess;
Expand Down Expand Up @@ -50,7 +51,13 @@ protected function configure()
'bin',
InputArgument::REQUIRED,
$this->trans('commands.exec.arguments.bin')
);
)->addOption(
'working-directory',
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.exec.options.working-directory')
)
;
}

/**
Expand All @@ -60,6 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$bin = $input->getArgument('bin');
$workingDirectory = $input->getOption('working-directory');

if (!$bin) {
$io->error(
Expand All @@ -69,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

if (!$this->shellProcess->exec($bin)) {
if (!$this->shellProcess->exec($bin, $workingDirectory)) {
$io->error(
sprintf(
$this->trans('commands.exec.messages.invalid-bin')
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/ShellProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct($appRoot)
*/
public function exec($command, $workingDirectory=null)
{
if (!$workingDirectory) {
if (!$workingDirectory || $workingDirectory==='') {
$workingDirectory = $this->appRoot;
}
$this->process = new Process($command);
Expand Down

0 comments on commit 24940dd

Please sign in to comment.