Skip to content

Commit a121f79

Browse files
authored
Merge pull request #53 from brainexe/master
Symfony 4.4/5.0 compatibility
2 parents 1468840 + 209d917 commit a121f79

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Shell completion for Symfony Console based scripts",
44
"license": "MIT",
55
"require": {
6-
"symfony/console": "^2.5|^3|^4",
7-
"symfony/process": "^2.5|^3|^4",
6+
"symfony/console": "^2.5|^3|^4|^5",
7+
"symfony/process": "^2.5|^3|^4|^5",
88
"ext-simplexml": "*"
99
},
1010
"require-dev": {

src/DumpCommand.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bamarni\Symfony\Console\Autocomplete;
44

5+
use InvalidArgumentException;
6+
use RuntimeException;
57
use Symfony\Component\Console\Command\Command;
68
use Symfony\Component\Console\Input\InputInterface;
79
use Symfony\Component\Console\Input\InputArgument;
@@ -26,13 +28,13 @@ protected function configure()
2628
;
2729
}
2830

29-
protected function execute(InputInterface $input, OutputInterface $output)
31+
protected function execute(InputInterface $input, OutputInterface $output): int
3032
{
3133
$shell = $input->getOption('shell');
3234
$script = $input->getArgument('script');
3335

3436
if (!in_array($shell, array('bash', 'zsh', 'fish'))) {
35-
throw new \InvalidArgumentException(sprintf(
37+
throw new InvalidArgumentException(sprintf(
3638
'Completion is only available for Bash, Fish and Zsh, "%s" given.',
3739
$shell
3840
));
@@ -66,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6668

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

69-
return;
71+
return 0;
7072
}
7173

7274
/* =====================================
@@ -76,10 +78,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
7678
$scriptOptions = $input->getOption('script-options');
7779

7880
// find all commands
79-
$process = new Process($script . ' list ' . $scriptOptions . ' --format=xml');
81+
$command = $script . ' list ' . $scriptOptions . ' --format=xml';
82+
if (method_exists(Process::class, 'fromShellCommandline')) {
83+
// Symfony 4+
84+
$process = Process::fromShellCommandline($command);
85+
} else {
86+
// old Symfony way
87+
$process = new Process($command);
88+
}
8089
$process->run();
8190
if (!$process->isSuccessful()) {
82-
throw new \RuntimeException($process->getErrorOutput());
91+
throw new RuntimeException($process->getErrorOutput());
8392
}
8493

8594
$xmlCommands = $process->getOutput();
@@ -133,6 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
133142
'commands_options_descriptions' => $commandsOptionsDescriptions,
134143
'tools' => $tools,
135144
)));
145+
146+
return 0;
136147
}
137148

138149
private function render($template, $vars)

0 commit comments

Comments
 (0)