Skip to content

Commit

Permalink
Merge pull request #53 from brainexe/master
Browse files Browse the repository at this point in the history
Symfony 4.4/5.0 compatibility
  • Loading branch information
rquadling authored Mar 4, 2020
2 parents 1468840 + 209d917 commit a121f79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 16 additions & 5 deletions src/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
));
Expand Down Expand Up @@ -66,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->write($this->render($shell . '/default', compact('tools')));

return;
return 0;
}

/* =====================================
Expand All @@ -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();
Expand Down Expand Up @@ -133,6 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'commands_options_descriptions' => $commandsOptionsDescriptions,
'tools' => $tools,
)));

return 0;
}

private function render($template, $vars)
Expand Down

0 comments on commit a121f79

Please sign in to comment.