8000 [Console] Issue 43602 : Add fish completion by guillaume-a · Pull Request #43641 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Issue 43602 : Add fish completion #43641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Symfony/Component/Console/Command/CompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Completion\Output\BashCompletionOutput;
use Symfony\Component\Console\Completion\Output\CompletionOutputInterface;
use Symfony\Component\Console\Completion\Output\FishCompletionOutput;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -41,7 +42,10 @@ final class CompleteCommand extends Command
public function __construct(array $completionOutputs = [])
{
// must be set before the parent constructor, as the property value is used in configure()
$this->completionOutputs = $completionOutputs + ['bash' => BashCompletionOutput::class];
$this->completionOutputs = $completionOutputs + [
'bash' => BashCompletionOutput::class,
'fish' => FishCompletionOutput::class,
];

parent::__construct();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Console\Completion\Output;

use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @author Guillaume Aveline <guillaume.aveline@pm.me>
*/
class FishCompletionOutput implements CompletionOutputInterface
{
public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
{
$values = $suggestions->getValueSuggestions();
foreach ($suggestions->getOptionSuggestions() as $option) {
$values[] = '--'.$option->getName();
}
$output->write(implode("\n", $values));
}
}
29 changes: 29 additions & 0 deletions src/Symfony/Component/Console/Resources/completion.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is part of the Symfony package.
#
# (c) Fabien Potencier <fabien@symfony.com>
#
# For the full copyright and license information, please view
# https://symfony.com/doc/current/contributing/code/license.html

function _sf_{{ COMMAND_NAME }}
set sf_cmd (commandline -o)
set c (math (count (commandline -oc))) - 1)

set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S{{ VERSION }}"

for i in $sf_cmd
if [ $i != "" ]
set completecmd $completecmd "-i$i"
end
end

set completecmd $completecmd "-c$c"

set sfcomplete ($completecmd)

for i in $sfcomplete
echo $i
end
end

complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testRequiredShellOption()

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function provideCompletionSuggestions()
{
yield 'shell' => [
[''],
['bash'],
['bash', 'fish'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The shell type (\"bash\")",
"description": "The shell type (\"bash\", \"fish\")",
"default": null
},
"current": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<arguments/>
<options>
<option name="--shell" shortcut="-s" accept_value="1" is_value_required="1" is_multiple="0">
<description>The shell type ("bash")</description>
<description>The shell type ("bash", "fish")</description>
<defaults/>
</option>
<option name="--input" shortcut="-i" accept_value="1" is_value_required="1" is_multiple="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "The shell type (\"bash\")",
"description": &quo 9E12 t;The shell type (\"bash\", \"fish\")",
"default": null
},
"current": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<arguments/>
<options>
<option name="--shell" shortcut="-s" accept_value="1" is_value_required="1" is_multiple="0">
<description>The shell type ("bash")</description>
<description>The shell type ("bash", "fish")</description>
<defaults/>
</option>
<option name="--input" shortcut="-i" accept_value="1" is_value_required="1" is_multiple="1">
Expand Down
0