Skip to content

Commit 0fd9ecf

Browse files
committed
Add suggestions for the option 'format' of lints commands: twig, yaml and xliff
1 parent b33c743 commit 0fd9ecf

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Command/LintCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Console\CI\GithubActionReporter;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Exception\InvalidArgumentException;
1719
use Symfony\Component\Console\Exception\RuntimeException;
1820
use Symfony\Component\Console\Input\InputArgument;
@@ -284,4 +286,11 @@ private function getContext(string $template, int $line, int $context = 3)
284286

285287
return $result;
286288
}
289+
290+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
291+
{
292+
if ($input->mustSuggestOptionValuesFor('format')) {
293+
$suggestions->suggestValues(['txt', 'json', 'github']);
294+
}
295+
}
287296
}

Tests/Command/LintCommandTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Command\LintCommand;
1616
use Symfony\Component\Console\Application;
17+
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1820
use Symfony\Component\Console\Tester\CommandTester;
1921
use Twig\Environment;
2022
use Twig\Loader\FilesystemLoader;
@@ -134,7 +136,27 @@ public function testLintAutodetectsGithubActionEnvironment()
134136
}
135137
}
136138

139+
/**
140+
* @dataProvider provideCompletionSuggestions
141+
*/
142+
public function testComplete(array $input, array $expectedSuggestions)
143+
{
144+
$tester = new CommandCompletionTester($this->createCommand());
145+
146+
$this->assertSame($expectedSuggestions, $tester->complete($input));
147+
}
148+
149+
public function provideCompletionSuggestions()
150+
{
151+
yield 'option' => [['--format', ''], ['txt', 'json', 'github']];
152+
}
153+
137154
private function createCommandTester(): CommandTester
155+
{
156+
return new CommandTester($this->createCommand());
157+
}
158+
159+
private function createCommand(): Command
138160
{
139161
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
140162
$environment->addFilter(new TwigFilter('deprecated_filter', function ($v) {
@@ -145,9 +167,8 @@ private function createCommandTester(): CommandTester
145167

146168
$application = new Application();
147169
$application->add($command);
148-
$command = $application->find('lint:twig');
149170

150-
return new CommandTester($command);
171+
return $application->find('lint:twig');
151172
}
152173

153174
private function createFile($content): string

0 commit comments

Comments
 (0)