Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73f8713

Browse files
committed
feature #53986 [Console] Add descriptions to Fish completion output (adriaanzon)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [Console] Add descriptions to Fish completion output | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT This improves the completion output for the Fish shell to include descriptions. The `-a` option of Fish's [complete](https://fishshell.com/docs/current/cmds/complete.html) command accepts a list where each line is an argument with an optional description, separated by a tab. The fish script doesn't need to change, making this change backwards compatible. Since the output is now identical to that of `ZshCompletionOutput`, code duplication could still be reduced by extracting to an abstract class (e.g. `TabSeparatedCompletionOutput`) that gets extended by `FishCompletionOutput` and `ZshCompletionOutput`. Commits ------- 1cfd6df [Console] Add descriptions to Fish completion output
2 parents 8d352bc + 1cfd6df commit 73f8713

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ class FishCompletionOutput implements CompletionOutputInterface
2121
{
2222
public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
2323
{
24-
$values = $suggestions->getValueSuggestions();
24+
$values = [];
25+
foreach ($suggestions->getValueSuggestions() as $value) {
26+
$values[] = $value->getValue().($value->getDescription() ? "\t".$value->getDescription() : '');
27+
}
2528
foreach ($suggestions->getOptionSuggestions() as $option) {
26-
$values[] = '--'.$option->getName();
29+
$values[] = '--'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
2730
if ($option->isNegatable()) {
28-
$values[] = '--no-'.$option->getName();
31+
$values[] = '--no-'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
2932
}
3033
}
3134
$output->write(implode("\n", $values));

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ function _sf_{{ COMMAND_NAME }}
1919

2020
set completecmd $completecmd "-c$c"
2121

22-
set sfcomplete ($completecmd)
23-
24-
for i in $sfcomplete
25-
echo $i
26-
end
22+
$completecmd
2723
end
2824

2925
complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function getCompletionOutput(): CompletionOutputInterface
2323

2424
public function getExpectedOptionsOutput(): string
2525
{
26-
return "--option1\n--negatable\n--no-negatable";
26+
return "--option1\tFirst Option\n--negatable\tCan be negative\n--no-negatable\tCan be negative";
2727
}
2828

2929
public function getExpectedValuesOutput(): string
3030
{
31-
return "Green\nRed\nYellow";
31+
return "Green\tBeans are green\nRed\tRose are red\nYellow\tCanaries are yellow";
3232
}
3333
}

0 commit comments

Comments
 (0)