Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Exec command * Implement Process component * Handle the output of exec * Use shellprocess * Update parameters for exec * Improve the comments * Fix duplication
- Loading branch information
Showing
4 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
exec: | ||
class: Drupal\Console\Command\Exec\ExecCommand | ||
tags: | ||
- { name: console.command } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
description: 'Execute an external command.' | ||
arguments: | ||
bin: 'Executable name.' | ||
messages: | ||
success: 'Executed the command.' | ||
invalid-bin: 'Error executing the command.' | ||
missing-bin: 'Provide a executable.' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\Console\Command\Exec\ExecCommand. | ||
*/ | ||
|
||
namespace Drupal\Console\Command\Exec; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait; | ||
use Drupal\Console\Style\DrupalStyle; | ||
|
||
/** | ||
* Class ExecCommand | ||
* @package Drupal\Console\Command\Exec | ||
*/ | ||
class ExecCommand extends Command | ||
{ | ||
use ContainerAwareCommandTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('exec') | ||
->setDescription($this->trans('commands.exec.description')) | ||
->addArgument( | ||
'bin', | ||
InputArgument::REQUIRED, | ||
$this->trans('commands.exec.arguments.bin') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new DrupalStyle($input, $output); | ||
$bin = $input->getArgument('bin'); | ||
|
||
if (!$bin) { | ||
$io->error( | ||
$this->trans('commands.exec.messages.missing-bin') | ||
); | ||
return 1; | ||
} | ||
|
||
$shellProcess = $this->get('shell_process'); | ||
if ($shellProcess->exec($bin, TRUE)) { | ||
$io->success( | ||
sprintf( | ||
$this->trans('commands.exec.messages.success'), | ||
$bin | ||
) | ||
); | ||
} | ||
else { | ||
$io->error( | ||
sprintf( | ||
$this->trans('commands.exec.messages.invalid-bin') | ||
) | ||
); | ||
return 1; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters