shellProcess = $shellProcess; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('exec') ->setDescription($this->trans('commands.exec.description')) ->addArgument( 'bin', InputArgument::REQUIRED, $this->trans('commands.exec.arguments.bin') )->addOption( 'working-directory', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.exec.options.working-directory') ); } /** * {@inheritdoc} */ 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( $this->trans('commands.exec.messages.missing-bin') ); return 1; } $name = $bin; if ($index = stripos($name, " ")) { $name = substr($name, 0, $index); } $finder = new ExecutableFinder(); if (!$finder->find($name)) { $io->error( sprintf( $this->trans('commands.exec.messages.binary-not-found'), $name ) ); return 1; } if (!$this->shellProcess->exec($bin, $workingDirectory)) { $io->error( sprintf( $this->trans('commands.exec.messages.invalid-bin') ) ); $io->writeln($this->shellProcess->getOutput()); return 1; } $io->success( sprintf( $this->trans('commands.exec.messages.success'), $bin ) ); return 0; } }