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;
22 * @package Drupal\Console\Core\Command\Exec
24 class ExecCommand extends Command
31 protected $shellProcess;
34 * ExecCommand constructor.
35 * @param ShellProcess $shellProcess
37 public function __construct(ShellProcess $shellProcess)
39 $this->shellProcess = $shellProcess;
40 parent::__construct();
46 protected function configure()
50 ->setDescription($this->trans('commands.exec.description'))
53 InputArgument::REQUIRED,
54 $this->trans('commands.exec.arguments.bin')
58 InputOption::VALUE_OPTIONAL,
59 $this->trans('commands.exec.options.working-directory')
66 protected function execute(InputInterface $input, OutputInterface $output)
68 $io = new DrupalStyle($input, $output);
69 $bin = $input->getArgument('bin');
70 $workingDirectory = $input->getOption('working-directory');
74 $this->trans('commands.exec.messages.missing-bin')
81 if ($index = stripos($name, " ")) {
82 $name = substr($name, 0, $index);
85 $finder = new ExecutableFinder();
86 if (!$finder->find($name)) {
89 $this->trans('commands.exec.messages.binary-not-found'),
97 if (!$this->shellProcess->exec($bin, $workingDirectory)) {
100 $this->trans('commands.exec.messages.invalid-bin')
104 $io->writeln($this->shellProcess->getOutput());
111 $this->trans('commands.exec.messages.success'),