|
12 | 12 | namespace Symfony\Component\VarDumper\Command; |
13 | 13 |
|
14 | 14 | use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Completion\CompletionInput; |
| 16 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
15 | 17 | use Symfony\Component\Console\Exception\InvalidArgumentException; |
16 | 18 | use Symfony\Component\Console\Input\InputInterface; |
17 | 19 | use Symfony\Component\Console\Input\InputOption; |
@@ -55,10 +57,8 @@ public function __construct(DumpServer $server, array $descriptors = []) |
55 | 57 |
|
56 | 58 | protected function configure() |
57 | 59 | { |
58 | | - $availableFormats = implode(', ', array_keys($this->descriptors)); |
59 | | - |
60 | 60 | $this |
61 | | - ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', $availableFormats), 'cli') |
| 61 | + ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli') |
62 | 62 | ->setDescription(self::$defaultDescription) |
63 | 63 | ->setHelp(<<<'EOF' |
64 | 64 | <info>%command.name%</info> starts a dump server that collects and displays |
@@ -99,4 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
99 | 99 |
|
100 | 100 | return 0; |
101 | 101 | } |
| 102 | + |
| 103 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
| 104 | + { |
| 105 | + if ($input->mustSuggestOptionValuesFor('format')) { |
| 106 | + $suggestions->suggestValues($this->getAvailableFormats()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + private function getAvailableFormats(): array |
| 111 | + { |
| 112 | + return array_keys($this->descriptors); |
| 113 | + } |
102 | 114 | } |
0 commit comments