From 441c3061fb646284caa7c01789296c1707454c6e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 13 May 2022 12:06:30 +0200 Subject: [PATCH 1/2] Fix aliases handling in command name completion --- Application.php | 15 ++++++++++++--- Command/CompleteCommand.php | 3 ++- Tests/Command/CompleteCommandTest.php | 10 +++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Application.php b/Application.php index 3decfc04b..366d61204 100644 --- a/Application.php +++ b/Application.php @@ -363,9 +363,18 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType() && 'command' === $input->getCompletionName() ) { - $suggestions->suggestValues(array_filter(array_map(function (Command $command) { - return $command->isHidden() ? null : $command->getName(); - }, $this->all()))); + $commandNames = []; + foreach ($this->all() as $name => $command) { + // skip hidden commands and aliased commands as they already get added below + if ($command->isHidden() || $command->getName() !== $name) { + continue; + } + $commandNames[] = $command->getName(); + foreach ($command->getAliases() as $name) { + $commandNames[] = $name; + } + } + $suggestions->suggestValues(array_filter($commandNames)); return; } diff --git a/Command/CompleteCommand.php b/Command/CompleteCommand.php index 97357d673..a94021ce4 100644 --- a/Command/CompleteCommand.php +++ b/Command/CompleteCommand.php @@ -105,11 +105,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } elseif ( $completionInput->mustSuggestArgumentValuesFor('command') && $command->getName() !== $completionInput->getCompletionValue() + && !\in_array($completionInput->getCompletionValue(), $command->getAliases(), true) ) { $this->log(' No command found, completing using the Application class.'); // expand shortcut names ("cache:cl") into their full name ("cache:clear") - $suggestions->suggestValue($command->getName()); + $suggestions->suggestValues(array_filter(array_merge([$command->getName()], $command->getAliases()))); } else { $command->mergeApplicationDefinition(); $completionInput->bind($command->getDefinition()); diff --git a/Tests/Command/CompleteCommandTest.php b/Tests/Command/CompleteCommandTest.php index 189928897..f3ffe7b50 100644 --- a/Tests/Command/CompleteCommandTest.php +++ b/Tests/Command/CompleteCommandTest.php @@ -102,9 +102,10 @@ public function testCompleteCommandName(array $input, array $suggestions) public function provideCompleteCommandNameInputs() { - yield 'empty' => [['bin/console'], ['help', 'list', 'completion', 'hello']]; - yield 'partial' => [['bin/console', 'he'], ['help', 'list', 'completion', 'hello']]; - yield 'complete-shortcut-name' => [['bin/console', 'hell'], ['hello']]; + yield 'empty' => [['bin/console'], ['help', 'list', 'completion', 'hello', 'ahoy']]; + yield 'partial' => [['bin/console', 'he'], ['help', 'list', 'completion', 'hello', 'ahoy']]; + yield 'complete-shortcut-name' => [['bin/console', 'hell'], ['hello', 'ahoy']]; + yield 'complete-aliases' => [['bin/console', 'ah'], ['hello', 'ahoy']]; } /** @@ -120,6 +121,8 @@ public function provideCompleteCommandInputDefinitionInputs() { yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']]; + yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']]; } private function execute(array $input) @@ -134,6 +137,7 @@ class CompleteCommandTest_HelloCommand extends Command public function configure(): void { $this->setName('hello') + ->setAliases(['ahoy']) ->addArgument('name', InputArgument::REQUIRED) ; } From cce7a9f99e22937a71a16b23afa762558808d587 Mon Sep 17 00:00:00 2001 From: Kris Kelly Date: Tue, 19 Apr 2022 18:05:47 +0100 Subject: [PATCH 2/2] [Console] Fixes "Incorrectly nested style tag found" error when using multi-line header content --- Helper/Table.php | 2 +- Tests/Helper/TableTest.php | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Helper/Table.php b/Helper/Table.php index 141e7d490..99496b1c7 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -586,7 +586,7 @@ private function buildTableRows(array $rows): TableRows } $escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell))); $cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped; - $lines = explode("\n", str_replace("\n", "\n", $cell)); + $lines = explode("\n", str_replace("\n", "\n", $cell)); foreach ($lines as $lineKey => $line) { if ($colspan > 1) { $line = new TableCell($line, ['colspan' => $colspan]); diff --git a/Tests/Helper/TableTest.php b/Tests/Helper/TableTest.php index 14ea5c6bb..c0f3f96b2 100644 --- a/Tests/Helper/TableTest.php +++ b/Tests/Helper/TableTest.php @@ -615,8 +615,8 @@ public function renderProvider() 'default', <<<'TABLE' +-------+------------+ -| Dont break | -| here | +| Dont break | +| here | +-------+------------+ | foo | Dont break | | bar | here | @@ -1078,6 +1078,26 @@ public function renderSetTitle() | 80-902734-1-6 | And Then There Were None | Agatha Christie | +---------------+--------- Page 1/2 -------+------------------+ +TABLE + , + true, + ], + 'header contains multiple lines' => [ + 'Multiline'."\n".'header'."\n".'here', + 'footer', + 'default', + <<<'TABLE' ++---------------+--- Multiline +header +here +------------------+ +| ISBN | Title | Author | ++---------------+--------------------------+------------------+ +| 99921-58-10-7 | Divine Comedy | Dante Alighieri | +| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | +| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | +| 80-902734-1-6 | And Then There Were None | Agatha Christie | ++---------------+---------- footer --------+------------------+ + TABLE ], [