8000 feature #43680 Add suggestions for the option 'format' of lints comma… · symfony/symfony@567eb19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 567eb19

Browse files
committed
feature #43680 Add suggestions for the option 'format' of lints commands: twig, yaml and xliff (makraz)
This PR was merged into the 5.4 branch. Discussion ---------- Add suggestions for the option 'format' of lints commands: twig, yaml and xliff | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #43594 | License | MIT | Doc PR | - Adding Bash completion for the following commands: - lint:twig (--format) - lint:xliff (--format) - lint:yaml (--format) Commits ------- 5bbfc34 Add suggestions for the option 'format' of lints commands: twig, yaml and xliff
2 parents ff70bd1 + 5bbfc34 commit 567eb19

File tree

6 files changed

+98
-7
lines changed

6 files changed

+98
-7
lines changed

src/Symfony/Bridge/Twig/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
}

src/Symfony/Bridge/Twig/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

src/Symfony/Component/Translation/Command/XliffLintCommand.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\RuntimeException;
1719
use Symfony\Component\Console\Input\InputArgument;
1820
use Symfony\Component\Console\Input\InputInterface;
@@ -274,4 +276,11 @@ private function getTargetLanguageFromFile(\DOMDocument $xliffContents): ?string
274276

275277
return null;
276278
}
279+
280+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
281+
{
282+
if ($input->mustSuggestOptionValuesFor('format')) {
283+
$suggestions->suggestValues(['txt', 'json', 'github']);
284+
}
285+
}
277286
}

src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
16+
use Symfony\Component\Console\Command\Command;
1617
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1719
use Symfony\Component\Console\Tester\CommandTester;
1820
use Symfony\Component\Translation\Command\XliffLintCommand;
1921

@@ -201,7 +203,7 @@ private function createFile($sourceContent = 'note', $targetLanguage = 'en', $fi
201203
return $filename;
202204
}
203205

204-
private function createCommandTester($requireStrictFileNames = true, $application = null): CommandTester
206+
private function createCommand($requireStrictFileNames = true, $application = null): Command
205207
{
206208
if (!$application) {
207209
$application = new Application();
@@ -214,7 +216,12 @@ private function createCommandTester($requireStrictFileNames = true, $applicatio
214216
$command->setApplication($application);
215217
}
216218

217-
return new CommandTester($command);
219+
return $command;
220+
}
221+
222+
private function createCommandTester($requireStrictFileNames = true, $application = null): CommandTester
223+
{
224+
return new CommandTester($this->createCommand($requireStrictFileNames, $application));
218225
}
219226

220227
protected function setUp(): void
@@ -244,4 +251,19 @@ public function provideStrictFilenames()
244251
yield [true, '%locale%.messages.xlf', 'en', true];
245252
yield [true, '%locale%.messages.xlf', 'es', true];
246253
}
254+
255+
/**
256+
* @dataProvider provideCompletionSuggestions
257+
*/
258+
public function testComplete(array $input, array $expectedSuggestions)
259+
{
260+
$tester = new CommandCompletionTester($this->createCommand());
261+
262+
$this->assertSame($expectedSuggestions, $tester->complete($input));
263+
}
264+
265+
public function provideCompletionSuggestions()
266+
{
267+
yield 'option' => [['--format', ''], ['txt', 'json', 'github']];
268+
}
247269
}

src/Symfony/Component/Yaml/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;
@@ -277,4 +279,11 @@ private function isReadable(string $fileOrDirectory): bool
277279

278280
return $default($fileOrDirectory);
279281
}
282+
283+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
284+
{
285+
if ($input->mustSuggestOptionValuesFor('format')) {
286+
$suggestions->suggestValues(['txt', 'json', 'github']);
287+
}
288+
}
280289
}

src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\CI\GithubActionReporter;
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 Symfony\Component\Yaml\Command\LintCommand;
2022

@@ -163,6 +165,21 @@ public function testLintFileNotReadable()
163165
$tester->execute(['filename' => $filename], ['decorated' => false]);
164166
}
165167

168+
/**
169+
* @dataProvider provideCompletionSuggestions
170+
*/
171+
public function testComplete(array $input, array $expectedSuggestions)
172+
{
173+
$tester = new CommandCompletionTester($this->createCommand());
174+
175+
$this->assertSame($expectedSuggestions, $tester->complete($input));
176+
}
177+
178+
public function provideCompletionSuggestions()
179+
{
180+
yield 'option' => [['--format', ''], ['txt', 'json', 'github']];
181+
}
182+
166183
private function createFile($content): string
167184
{
168185
$filename = tempnam(sys_get_temp_dir().'/framework-yml-lint-test', 'sf-');
@@ -173,13 +190,17 @@ private function createFile($content): string
173190
return $filename;
174191
}
175192

176-
protected function createCommandTester(): CommandTester
9238
193+
protected function createCommand(): Command
177194
{
178195
$application = new Application();
179196
$application->add(new LintCommand());
180-
$command = $application->find('lint:yaml');
181197

182-
return new CommandTester($command);
198+
return $application->find('lint:yaml');
199+
}
200+
201+
protected function createCommandTester(): CommandTester
202+
{
203+
return new CommandTester($this->createCommand());
183204
}
184205

185206
protected function setUp(): void

0 commit comments

Comments
 (0)
0