diff --git a/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php b/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php index ead9d5bd05b4a..3a6959522ec0f 100644 --- a/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php +++ b/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php @@ -12,6 +12,8 @@ namespace Symfony\Component\VarDumper\Command; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Completion\CompletionInput; +use Symfony\Component\Console\Completion\CompletionSuggestions; use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -55,10 +57,8 @@ public function __construct(DumpServer $server, array $descriptors = []) protected function configure() { - $availableFormats = implode(', ', array_keys($this->descriptors)); - $this - ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', $availableFormats), 'cli') + ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli') ->setDescription(self::$defaultDescription) ->setHelp(<<<'EOF' %command.name% starts a dump server that collects and displays @@ -99,4 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } + + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void + { + if ($input->mustSuggestOptionValuesFor('format')) { + $suggestions->suggestValues($this->getAvailableFormats()); + } + } + + private function getAvailableFormats(): array + { + return array_keys($this->descriptors); + } } diff --git a/src/Symfony/Component/VarDumper/Tests/Command/ServerDumpCommandTest.php b/src/Symfony/Component/VarDumper/Tests/Command/ServerDumpCommandTest.php new file mode 100644 index 0000000000000..f2025cf9bde3f --- /dev/null +++ b/src/Symfony/Component/VarDumper/Tests/Command/ServerDumpCommandTest.php @@ -0,0 +1,34 @@ +createCommand()); + + $this->assertSame($expectedSuggestions, $tester->complete($input)); + } + + public function provideCompletionSuggestions() + { + yield 'option --format' => [ + ['--format', ''], + ['cli', 'html'], + ]; + } + + private function createCommand(): ServerDumpCommand + { + return new ServerDumpCommand($this->createMock(DumpServer::class)); + } +}