5 * Contains \Drupal\Console\Core\Command\Exec\ExecCommand.
8 namespace Drupal\Console\Core\Command\Exec;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Process\ExecutableFinder;
15 use Drupal\Console\Core\Utils\ShellProcess;
16 use Drupal\Console\Core\Command\Command;
21 * @package Drupal\Console\Core\Command\Exec
23 class ExecCommand extends Command
28 protected $shellProcess;
31 * ExecCommand constructor.
33 * @param ShellProcess $shellProcess
35 public function __construct(ShellProcess $shellProcess)
37 $this->shellProcess = $shellProcess;
38 parent::__construct();
44 protected function configure()
48 ->setDescription($this->trans('commands.exec.description'))
51 InputArgument::REQUIRED,
52 $this->trans('commands.exec.arguments.bin')
56 InputOption::VALUE_OPTIONAL,
57 $this->trans('commands.exec.options.working-directory')
64 protected function execute(InputInterface $input, OutputInterface $output)
66 $bin = $input->getArgument('bin');
67 $workingDirectory = $input->getOption('working-directory');
70 $this->getIo()->error(
71 $this->trans('commands.exec.messages.missing-bin')
78 if ($index = stripos($name, " ")) {
79 $name = substr($name, 0, $index);
82 $finder = new ExecutableFinder();
83 if (!$finder->find($name)) {
84 $this->getIo()->error(
86 $this->trans('commands.exec.messages.binary-not-found'),
94 if (!$this->shellProcess->exec($bin, $workingDirectory)) {
95 $this->getIo()->error(
97 $this->trans('commands.exec.messages.invalid-bin')
101 $this->getIo()->writeln($this->shellProcess->getOutput());
106 $this->getIo()->success(
108 $this->trans('commands.exec.messages.success'),