From 3aac1c4ce9280a23e8f6dbddd23c5585bb9268e9 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Thu, 5 May 2022 14:54:11 +0200 Subject: [PATCH 1/6] [Console] Better required argument check in InputArgument --- Input/InputArgument.php | 2 +- Tests/Input/InputArgumentTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Input/InputArgument.php b/Input/InputArgument.php index 085aca5a7..accd4d0c5 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -92,7 +92,7 @@ public function isArray() */ public function setDefault($default = null) { - if (self::REQUIRED === $this->mode && null !== $default) { + if ($this->isRequired() && null !== $default) { throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); } diff --git a/Tests/Input/InputArgumentTest.php b/Tests/Input/InputArgumentTest.php index 4e583888a..9dae4e2ca 100644 --- a/Tests/Input/InputArgumentTest.php +++ b/Tests/Input/InputArgumentTest.php @@ -88,6 +88,14 @@ public function testSetDefaultWithRequiredArgument() $argument->setDefault('default'); } + public function testSetDefaultWithRequiredArrayArgument() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Cannot set a default value except for InputArgument::OPTIONAL mode.'); + $argument = new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY); + $argument->setDefault([]); + } + public function testSetDefaultWithArrayArgument() { $this->expectException(\LogicException::class); From cf62f0807b6583f73cb4b0d919a7c6d25b019b88 Mon Sep 17 00:00:00 2001 From: Sergei Shitikov Date: Sun, 8 May 2022 14:34:08 +0200 Subject: [PATCH 2/6] Suppress unhandled error in some specific use-cases. --- Command/DumpCompletionCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/DumpCompletionCommand.php b/Command/DumpCompletionCommand.php index f48aa9637..dc0cfaef7 100644 --- a/Command/DumpCompletionCommand.php +++ b/Command/DumpCompletionCommand.php @@ -41,7 +41,7 @@ protected function configure() { $fullCommand = $_SERVER['PHP_SELF']; $commandName = basename($fullCommand); - $fullCommand = realpath($fullCommand) ?: $fullCommand; + $fullCommand = @realpath($fullCommand) ?: $fullCommand; $this ->setHelp(<< Date: Mon, 9 May 2022 22:12:16 +0200 Subject: [PATCH 3/6] Fix CS in Console Table after #45565 --- Helper/Table.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Helper/Table.php b/Helper/Table.php index a5f34cb14..141e7d490 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -763,18 +763,18 @@ private function calculateColumnsWidth(iterable $groups) continue; } - foreach ($row as $i => $cell) { - if ($cell instanceof TableCell) { - $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell); - $textLength = Helper::strlen($textContent); - if ($textLength > 0) { - $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan())); - foreach ($contentColumns as $position => $content) { - $row[$i + $position] = $content; + foreach ($row as $i => $cell) { + if ($cell instanceof TableCell) { + $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell); + $textLength = Helper::strlen($textContent); + if ($textLength > 0) { + $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan())); + foreach ($contentColumns as $position => $content) { + $row[$i + $position] = $content; + } } } } - } $lengths[] = $this->getCellWidth($row, $column); } From 441c3061fb646284caa7c01789296c1707454c6e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 13 May 2022 12:06:30 +0200 Subject: [PATCH 4/6] 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 5/6] [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 ], [ From 829d5d1bf60b2efeb0887b7436873becc71a45eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 17 May 2022 22:50:08 +0200 Subject: [PATCH 6/6] Complete negatable options --- Completion/Output/BashCompletionOutput.php | 3 ++ Tests/Command/CompleteCommandTest.php | 4 +- .../Output/BashCompletionOutputTest.php | 33 ++++++++++++ .../Output/CompletionOutputTestCase.php | 51 +++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Tests/Completion/Output/BashCompletionOutputTest.php create mode 100644 Tests/Completion/Output/CompletionOutputTestCase.php diff --git a/Completion/Output/BashCompletionOutput.php b/Completion/Output/BashCompletionOutput.php index 8d5ffa6b6..c6f76eb8f 100644 --- a/Completion/Output/BashCompletionOutput.php +++ b/Completion/Output/BashCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->writeln(implode("\n", $values)); } diff --git a/Tests/Command/CompleteCommandTest.php b/Tests/Command/CompleteCommandTest.php index f3ffe7b50..642d5c69a 100644 --- a/Tests/Command/CompleteCommandTest.php +++ b/Tests/Command/CompleteCommandTest.php @@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti public function provideCompleteCommandInputDefinitionInputs() { - yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-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 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']]; } diff --git a/Tests/Completion/Output/BashCompletionOutputTest.php b/Tests/Completion/Output/BashCompletionOutputTest.php new file mode 100644 index 000000000..84ec56acc --- /dev/null +++ b/Tests/Completion/Output/BashCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\BashCompletionOutput; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; + +class BashCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new BashCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable".\PHP_EOL; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow".\PHP_EOL; + } +} diff --git a/Tests/Completion/Output/CompletionOutputTestCase.php b/Tests/Completion/Output/CompletionOutputTestCase.php new file mode 100644 index 000000000..c4551e5b6 --- /dev/null +++ b/Tests/Completion/Output/CompletionOutputTestCase.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Completion\CompletionSuggestions; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\StreamOutput; + +abstract class CompletionOutputTestCase extends TestCase +{ + abstract public function getCompletionOutput(): CompletionOutputInterface; + + abstract public function getExpectedOptionsOutput(): string; + + abstract public function getExpectedValuesOutput(): string; + + public function testOptionsOutput() + { + $options = [ + new InputOption('option1', 'o', InputOption::VALUE_NONE), + new InputOption('negatable', null, InputOption::VALUE_NEGATABLE), + ]; + $suggestions = new CompletionSuggestions(); + $suggestions->suggestOptions($options); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream)); + } + + public function testValuesOutput() + { + $suggestions = new CompletionSuggestions(); + $suggestions->suggestValues(['Green', 'Red', 'Yellow']); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream)); + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy