diff --git a/composer.json b/composer.json index f872c12..7041559 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "Shell completion for Symfony Console based scripts", "license": "MIT", "require": { - "symfony/console": "^2.5|^3|^4", - "symfony/process": "^2.5|^3|^4", + "symfony/console": "^2.5|^3|^4|^5", + "symfony/process": "^2.5|^3|^4|^5", "ext-simplexml": "*" }, "require-dev": { diff --git a/src/DumpCommand.php b/src/DumpCommand.php index 421ebd0..58d25b5 100644 --- a/src/DumpCommand.php +++ b/src/DumpCommand.php @@ -2,6 +2,8 @@ namespace Bamarni\Symfony\Console\Autocomplete; +use InvalidArgumentException; +use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; @@ -26,13 +28,13 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $shell = $input->getOption('shell'); $script = $input->getArgument('script'); if (!in_array($shell, array('bash', 'zsh', 'fish'))) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Completion is only available for Bash, Fish and Zsh, "%s" given.', $shell )); @@ -66,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->write($this->render($shell . '/default', compact('tools'))); - return; + return 0; } /* ===================================== @@ -76,10 +78,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $scriptOptions = $input->getOption('script-options'); // find all commands - $process = new Process($script . ' list ' . $scriptOptions . ' --format=xml'); + $command = $script . ' list ' . $scriptOptions . ' --format=xml'; + if (method_exists(Process::class, 'fromShellCommandline')) { + // Symfony 4+ + $process = Process::fromShellCommandline($command); + } else { + // old Symfony way + $process = new Process($command); + } $process->run(); if (!$process->isSuccessful()) { - throw new \RuntimeException($process->getErrorOutput()); + throw new RuntimeException($process->getErrorOutput()); } $xmlCommands = $process->getOutput(); @@ -133,6 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output) 'commands_options_descriptions' => $commandsOptionsDescriptions, 'tools' => $tools, ))); + + return 0; } private function render($template, $vars)