8000 Finish Zsh completion · symfony/symfony@3c2e1a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c2e1a4

Browse files
committed
Finish Zsh completion
1 parent 405f207 commit 3c2e1a4

File tree

9 files changed

+45
-79
lines changed

9 files changed

+45
-79
lines changed

src/Symfony/Component/Console/Command/CompleteCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
* Responsible for providing the values to the shell completion.
2929
*
3030
* @author Wouter de Jong <wouter@wouterj.nl>
31-
* @author Jitendra A <adhocore@gmail.com>
3231
*/
3332
#[AsCommand(name: '|_complete', description: 'Internal command to provide shell completion suggestions')]
3433
final class CompleteCommand extends Command
@@ -188,7 +187,6 @@ private function createCompletionInput(InputInterface $input): CompletionInput
188187
}
189188

190189
$completionInput = CompletionInput::fromTokens($input->getOption('input'), (int) $currentIndex);
191-
$completionInput->setShell($input->getOption('shell'));
192190

193191
try {
194192
$completionInput->bind($this->getApplication()->getDefinition());

src/Symfony/Component/Console/Command/DumpCompletionCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function configure()
4848
$shell = $this->guessShell();
4949
[$rcFile, $completionFile] = match ($shell) {
5050
'fish' => ['~/.config/fish/config.fish', "/etc/fish/completions/$commandName.fish"],
51+
'zsh' => ['~/.zshrc', '$fpath[1]/'.$commandName],
5152
default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"],
5253
};
5354

src/Symfony/Component/Console/Completion/CompletionInput.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* completion is expected.
2424
*
2525
* @author Wouter de Jong <wouter@wouterj.nl>
26-
* @author Jitendra A <adhocore@gmail.com>
2726
*/
2827
final class CompletionInput extends ArgvInput
2928
{
@@ -33,7 +32,6 @@ final class CompletionInput extends ArgvInput
3332
public const TYPE_NONE = 'none';
3433

3534
private $tokens;
36-
private $shell = '';
3735
private $currentIndex;
3836
private $completionType;
3937
private $completionName = null;
@@ -181,16 +179,6 @@ public function mustSuggestArgumentValuesFor(string $argumentName): bool
181179
return self::TYPE_ARGUMENT_VALUE === $this->getCompletionType() && $argumentName === $this->getCompletionName();
182180
}
183181

184-
public function setShell(string $shell): void
185-
{
186-
$this->shell = $shell;
187-
}
188-
189-
public function isShell(string $shell): bool
190-
{
191-
return $this->shell === $shell;
192-
}
193-
194182
protected function parseToken(string $token, bool $parseOptions): bool
195183
{
196184
try {

src/Symfony/Component/Console/Completion/Suggestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Wouter de Jong <wouter@wouterj.nl>
1818
*/
19-
class Suggestion
19+
class Suggestion implements \Stringable
2020
{
2121
public function __construct(
2222
private readonly string $value,

src/Symfony/Component/Console/Resources/completion.zsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _sf_{{ COMMAND_NAME }}() {
3131
fi
3232

3333
# Prepare the command to obtain completions
34-
requestComp="${words[0]} ${words[1]} _complete -szsh -S{{ VERSION }} -c$((CURRENT-1))" i=""
34+
requestComp="${words[0]} ${words[1]} _complete -szsh -a{{ VERSION }} -c$((CURRENT-1))" i=""
3535
for w in ${words[@]}; do
3636
w=$(printf -- '%b' "$w")
3737
# remove quotes from typed values
@@ -49,7 +49,7 @@ _sf_{{ COMMAND_NAME }}() {
4949
fi
5050
done
5151

52-
# Ensure atleast 1 input
52+
# Ensure at least 1 input
5353
if [ "${i}" = "" ]; then
5454
requestComp="${requestComp} -i\" \""
5555
else

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -125,57 +125,6 @@ public function provideCompleteCommandInputDefinitionInputs()
125125
yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']];
126126
}
127127

128-
/**
129-
* @dataProvider provideZshCompleteCommandNameInputs
130-
*/
131-
public function testZshCompleteCommandName(array $input, array $suggestions)
132-
{
133-
$this->execute(['--current' => '1', '--input' => $input, '--shell' => 'zsh']);
134-
$this->assertEquals(implode("\n", $suggestions).\PHP_EOL, $this->tester->getDisplay());
135-
}
136-
137-
public function provideZshCompleteCommandNameInputs()
138-
{
139-
yield 'empty' => [['bin/console'], [
140-
'help'."\t".'Display help for a command',
141-
'list'."\t".'List commands',
142-
'completion'."\t".'Dump the shell completion script',
143-
'hello'."\t".'Hello test command',
144-
'ahoy'."\t".'Hello test command',
145-
]];
146-
yield 'partial' => [['bin/console', 'he'], [
147-
'help'."\t".'Display help for a command',
148-
'list'."\t".'List commands',
149-
'completion'."\t".'Dump the shell completion script',
150-
'hello'."\t".'Hello test command',
151-
'ahoy'."\t".'Hello test command',
152-
]];
153-
yield 'complete-shortcut-name' => [['bin/console', 'hell'], ['hello', 'ahoy']];
154-
}
155-
156-
/**
157-
* @dataProvider provideZshCompleteCommandInputDefinitionInputs
158-
*/
159-
public function testZshCompleteCommandInputDefinition(array $input, array $suggestions)
160-
{
161-
$this->execute(['--current' => '2', '--input' => $input, '--shell' => 'zsh']);
162-
$this->assertEquals(implode("\n", $suggestions).\PHP_EOL, $this->tester->getDisplay());
163-
}
164-
165-
public function provideZshCompleteCommandInputDefinitionInputs()
166-
{
167-
yield 'definition' => [['bin/console', 'hello', '-'], [
168-
'--help'."\t".'Display help for the given command. When no command is given display help for the list command',
169-
'--quiet'."\t".'Do not output any message',
170-
'--verbose'."\t".'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug',
171-
'--version'."\t".'Display this application version',
172-
'--ansi'."\t".'Force (or disable --no-ansi) ANSI output',
173-
'--no-ansi'."\t".'Force (or disable --no-ansi) ANSI output',
174-
'--no-interaction'."\t".'Do not ask any interactive question',
175-
]];
176-
yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']];
177-
}
178-
179128
private function execute(array $input)
180129
{
181130
// run in verbose mode to assert exceptions

src/Symfony/Component/Console/Tests/Completion/CompletionInputTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,4 @@ public function provideFromStringData()
132132
yield ['bin/console cache:clear "multi word string"', ['bin/console', 'cache:clear', '"multi word string"']];
133133
yield ['bin/console cache:clear \'multi word string\'', ['bin/console', 'cache:clear', '\'multi word string\'']];
134134
}
135-
136-
public function testShell()
137-
{
138-
$input = CompletionInput::fromString('bin/console cache:clear \'multi word string\'', 1);
139-
$input->setShell('zsh');
140-
141-
$this->assertTrue($input->isShell('zsh'));
142-
}
143135
}

src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Completion\CompletionSuggestions;
1616
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
17+
use Symfony\Component\Console\Completion\Suggestion;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\StreamOutput;
1920

@@ -28,8 +29,8 @@ abstract public function getExpectedValuesOutput(): string;
2829
public function testOptionsOutput()
2930
{
3031
$options = [
31-
new InputOption('option1', 'o', InputOption::VALUE_NONE),
32-
new InputOption('negatable', null, InputOption::VALUE_NEGATABLE),
32+
new InputOption('option1', 'o', InputOption::VALUE_NONE, 'First Option'),
33+
new InputOption('negatable', null, InputOption::VALUE_NEGATABLE, 'Can be negative'),
3334
];
3435
$suggestions = new CompletionSuggestions();
3536
$suggestions->suggestOptions($options);
@@ -42,7 +43,11 @@ public function testOptionsOutput()
4243
public function testValuesOutput()
4344
{
4445
$suggestions = new CompletionSuggestions();
45-
$suggestions->suggestValues(['Green', 'Red', 'Yellow']);
46+
$suggestions->suggestValues([
47+
new Suggestion('Green', 'Beans are green'),
48+
new Suggestion('Red', 'Rose are red'),
49+
new Suggestion('Yellow', 'Canaries are yellow'),
50+
]);
4651
$stream = fopen('php://memory', 'rw+');
4752
$this->getCompletionOutput()->write($suggestions, new StreamOutput($stream));
4853
fseek($stream, 0);
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\CompletionOutputInterface;
15+
use Symfony\Component\Console\Completion\Output\ZshCompletionOutput;
16+
17+
class ZshCompletionOutputTest extends CompletionOutputTestCase
18+
{
19+
public function getCompletionOutput(): CompletionOutputInterface
20+
{
21+
return new ZshCompletionOutput();
22+
}
23+
24+
public function getExpectedOptionsOutput(): string
25+
{
26+
return "--option1\tFirst Option\n--negatable\tCan be negative\n--no-negatable\tCan be negative\n";
27+
}
28+
29+
public function getExpectedValuesOutput(): string
30+
{
31+
return "Green\tBeans are green\nRed\tRose are red\nYellow\tCanaries are yellow\n";
32+
}
33+
}

0 commit comments

Comments
 (0)
0