5 * Contains \Drupal\Console\Core\Command\Exec\ExecCommand.
8 namespace Drupal\Console\Core\Command\Exec;
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Input\InputOption;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Process\ExecutableFinder;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Utils\ShellProcess;
18 use Drupal\Console\Core\Style\DrupalStyle;
23 * @package Drupal\Console\Core\Command\Exec
25 class ExecCommand extends Command
32 protected $shellProcess;
35 * ExecCommand constructor.
37 * @param ShellProcess $shellProcess
39 public function __construct(ShellProcess $shellProcess)
41 $this->shellProcess = $shellProcess;
42 parent::__construct();
48 protected function configure()
52 ->setDescription($this->trans('commands.exec.description'))
55 InputArgument::REQUIRED,
56 $this->trans('commands.exec.arguments.bin')
60 InputOption::VALUE_OPTIONAL,
61 $this->trans('commands.exec.options.working-directory')
68 protected function execute(InputInterface $input, OutputInterface $output)
70 $io = new DrupalStyle($input, $output);
71 $bin = $input->getArgument('bin');
72 $workingDirectory = $input->getOption('working-directory');
76 $this->trans('commands.exec.messages.missing-bin')
83 if ($index = stripos($name, " ")) {
84 $name = substr($name, 0, $index);
87 $finder = new ExecutableFinder();
88 if (!$finder->find($name)) {
91 $this->trans('commands.exec.messages.binary-not-found'),
99 if (!$this->shellProcess->exec($bin, $workingDirectory)) {
102 $this->trans('commands.exec.messages.invalid-bin')
106 $io->writeln($this->shellProcess->getOutput());
113 $this->trans('commands.exec.messages.success'),