8000 Issue 43602 : Add fish completion · symfony/symfony@5335026 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5335026

Browse files
committed
Issue 43602 : Add fish completion
1 parent 6e88f92 commit 5335026

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Completion\CompletionSuggestions;
1616
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
1717
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
18+
use Symfony\Component\Console\Completion\Output\FishCompletionOutput;
1819
use Symfony\Component\Console\Exception\CommandNotFoundException;
1920
use Symfony\Component\Console\Exception\ExceptionInterface;
2021
use Symfony\Component\Console\Input\InputInterface;
@@ -41,7 +42,10 @@ final class CompleteCommand extends Command
4142
public function __construct(array $completionOutputs = [])
4243
{
4344
// must be set before the parent constructor, as the property value is used in configure()
44-
$this->completionOutputs = $completionOutputs + ['bash' => BashCompletionOutput::class];
45+
$this->completionOutputs = $completionOutputs + [
46+
'bash' => BashCompletionOutput::class,
47+
'fish' => FishCompletionOutput::class,
48+
];
4549

4650
parent::__construct();
4751
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\Completion\Output;
13+
14+
use Symfony\Component\Console\Completion\CompletionSuggestions;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
17+
/**
18+
* @author Guillaume Aveline <guillaume.aveline@pm.me>
19+
*/
20+
class FishCompletionOutput implements CompletionOutputInterface
21+
{
22+
public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
23+
{
24+
$values = $suggestions->getValueSuggestions();
25+
foreach ($suggestions->getOptionSuggestions() as $option) {
26+
$values[] = '--'.$option->getName();
27+
}
28+
$output->write(implode("\n", $values));
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is part of the Symfony package.
2+
#
3+
# (c) Fabien Potencier <fabien@symfony.com>
4+
#
5+
# For the full copyright and license information, please view
6+
# https://symfony.com/doc/current/contributing/code/license.html
7+
8+
function _sf_{{ COMMAND_NAME }}
9+
set sf_cmd (string split ' ' (commandline -c))
10+
set c (math (count (commandline -o))) - 1)
11+
12+
set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S{{ VERSION }}"
13+
14+
for i in $sf_cmd
15+
if [ $i != "" ]
16+
set completecmd $completecmd "-i$i"
17+
end
18+
end
19+
20+
set completecmd $completecmd "-c$c"
21+
22+
set sfcomplete ($completecmd)
23+
24+
for i in $sfcomplete
25+
echo $i
26+
end
27+
end
28+
29+
complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testRequiredShellOption()
4747

4848
public function testUnsupportedShellOption()
4949
{
50-
$this->expectExceptionMessage('Shell completion is not supported for your shell: "unsupported" (supported: "bash").');
50+
$this->expectExceptionMessage('Shell completion is not supported for your shell: "unsupported" (supported: "bash", "fish").');
5151
$this->execute(['--shell' => 'unsupported']);
5252
}
5353

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function provideCompletionSuggestions()
2323
{
2424
yield 'shell' => [
2525
[''],
26-
['bash'],
26+
['bash', 'fish'],
2727
];
2828
}
2929
}

src/Symfony/Component/Console/Tests/Fixtures/application_1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"accept_value": true,
9090
"is_value_required": true,
9191
"is_multiple": false,
92-
"description": "The shell type (\"bash\")",
92+
"description": "The shell type (\"bash\", \"fish\")",
9393
"default": null
9494
},
9595
"current": {

src/Symfony/Component/Console/Tests/Fixtures/application_1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<arguments/>
1111
<options>
1212
<option name="--shell" shortcut="-s" accept_value="1" is_value_required="1" is_multiple="0">
13-
<description>The shell type ("bash")</description>
13+
<description>The shell type ("bash", "fish")</description>
1414
<defaults/>
1515
</option>
1616
<option name="--input" shortcut="-i" accept_value="1" is_value_required="1" is_multiple="1">

src/Symfony/Component/Console/Tests/Fixtures/application_2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"accept_value": true,
9494
"is_value_required": true,
9595
"is_multiple": false,
96-
"description": "The shell type (\"bash\")",
96+
"description": "The shell type (\"bash\", \"fish\")",
9797
"default": null
9898
},
9999
"current": {

src/Symfony/Component/Console/Tests/Fixtures/application_2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<arguments/>
1111
<options>
1212
<option name="--shell" shortcut="-s" accept_value="1" is_value_required="1" is_multiple="0">
13-
<description>The shell type ("bash")</description>
13+
<description>The shell type ("bash", "fish")</description>
1414
<defaults/>
1515
</option>
1616
<option name="--input" shortcut="-i" accept_value="1" is_value_required="1" is_multiple="1">

0 commit comments

Comments
 (0)
0