8000 bug #46386 [Console]  Fix missing negative variation of negatable opt… · symfony/symfony@f79ed9a · GitHub
[go: up one dir, main page]

Skip to content

Commit f79ed9a

Browse files
committed
bug #46386 [Console]  Fix missing negative variation of negatable options in shell completion (GromNaN)
This PR was merged into the 5.4 branch. Discussion ---------- [Console]  Fix missing negative variation of negatable options in shell completion | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a Add negation of [negatable options](https://symfony.com/blog/new-in-symfony-5-3-negatable-command-options) in bash completion output. 2nd PR for Fish, targeting branch 6.1: #46387 Commits ------- a3da680 Complete negatable options
2 parents 87105b4 + a3da680 commit f79ed9a

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu
2424
$values = $suggestions->getValueSuggestions();
2525
foreach ($suggestions->getOptionSuggestions() as $option) {
2626
$values[] = '--'.$option->getName();
27+
if ($option->isNegatable()) {
28+
$values[] = '--no-'.$option->getName();
29+
}
2730
}
2831
$output->writeln(implode("\n", $values));
2932
}

src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti
119119

120120
public function provideCompleteCommandInputDefinitionInputs()
121121
{
122-
yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']];
122+
yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
123123
yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']];
124-
yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']];
124+
yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']];
125125
yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']];
126126
}
127127

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Completion\Output;
13+
14+
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
15+
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
16+
17+
class BashCompletionOutputTest extends CompletionOutputTestCase
18+
{
19+
public function getCompletionOutput(): CompletionOutputInterface
20+
{
21+
return new BashCompletionOutput();
22+
}
23+
24+
public function getExpectedOptionsOutput(): string
25+
{
26+
return "--option1\n--negatable\n--no-negatable".\PHP_EOL;
27+
}
28+
29+
public function getExpectedValuesOutput(): string
30+
{
31+
return "Green\nRed\nYellow".\PHP_EOL;
32+
}
33+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Completion\Output;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Completion\CompletionSuggestions;
16+
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
18+
use Symfony\Component\Console\Output\StreamOutput;
19+
20+
abstract class CompletionOutputTestCase extends TestCase
21+
{
22+
abstract public function getCompletionOutput(): CompletionOutputInterface;
23+
24+
abstract public function getExpectedOptionsOutput(): string;
25+
26+
abstract public function getExpectedValuesOutput(): string;
27+
28+
public function testOptionsOutput()
29+
{
30+
$options = [
31+
new InputOption('option1', 'o', InputOption::VALUE_NONE),
32+
new InputOption('negatable', null, InputOption::VALUE_NEGATABLE),
33+
];
34+
$suggestions = new CompletionSuggestions();
35+
$suggestions->suggestOptions($options);
36+
$stream = fopen('php://memory', 'rw+');
37+
$this->getCompletionOutput()->write($suggestions, new StreamOutput($stream));
38+
fseek($stream, 0);
39+
$this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream));
40+
}
41+
42+
public function testValuesOutput()
43+
{
44+
$suggestions = new CompletionSuggestions();
45+
$suggestions->suggestValues(['Green', 'Red', 'Yellow']);
46+
$stream = fopen('php://memory', 'rw+');
47+
$this->getCompletionOutput()->write($suggestions, new StreamOutput($stream));
48+
fseek($stream, 0);
49+
$this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream));
50+
}
51+
}

0 commit comments

Comments
 (0)
0