|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Console\Command;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Console\Completion\CompletionInput; |
| 15 | +use Symfony\Component\Console\Completion\CompletionInterface; |
| 16 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
14 | 17 | use Symfony\Component\Console\Input\InputArgument;
|
15 | 18 | use Symfony\Component\Console\Input\InputInterface;
|
16 | 19 | use Symfony\Component\Console\Input\InputOption;
|
|
23 | 26 | *
|
24 | 27 | * @author Wouter de Jong <wouter@wouterj.nl>
|
25 | 28 | */
|
26 |
| -final class DumpCompletionCommand extends Command |
| 29 | +final class DumpCompletionCommand extends Command implements CompletionInterface |
27 | 30 | {
|
28 | 31 | protected static $defaultName = 'completion';
|
29 | 32 | protected static $defaultDescription = 'Dump the shell completion script';
|
30 | 33 |
|
| 34 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
| 35 | + { |
| 36 | + if ($input->mustSuggestArgumentValuesFor('shell')) { |
| 37 | + $suggestions->suggestValues($this->getSupportedShells()); |
| 38 | + } |
| 39 | + } |
| 40 | + |
31 | 41 | protected function configure()
|
32 | 42 | {
|
33 | 43 | $fullCommand = $_SERVER['PHP_SELF'];
|
@@ -82,9 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
82 | 92 | $shell = $input->getArgument('shell') ?? self::guessShell();
|
83 | 93 | $completionFile = __DIR__.'/../Resources/completion.'.$shell;
|
84 | 94 | if (!file_exists($completionFile)) {
|
85 |
| - $supportedShells = array_map(function ($f) { |
86 |
| - return pathinfo($f, \PATHINFO_EXTENSION); |
87 |
| - }, glob(__DIR__.'/../Resources/completion.*')); |
| 95 | + $supportedShells = $this->getSupportedShells(); |
88 | 96 |
|
89 | 97 | ($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output)
|
90 | 98 | ->writeln(sprintf('<error>Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").</>', $shell, implode('", "', $supportedShells)));
|
@@ -113,4 +121,14 @@ private function tailDebugLog(string $commandName, OutputInterface $output): voi
|
113 | 121 | $output->write($line);
|
114 | 122 | });
|
115 | 123 | }
|
| 124 | + |
| 125 | + /** |
| 126 | + * @return string[] |
| 127 | + */ |
| 128 | + private function getSupportedShells(): array |
| 129 | + { |
| 130 | + return array_map(function ($f) { |
| 131 | + return pathinfo($f, \PATHINFO_EXTENSION); |
| 132 | + }, glob(__DIR__.'/../Resources/completion.*')); |
| 133 | + } |
116 | 134 | }
|
0 commit comments