Skip to content

Commit 2bc884f

Browse files
feature #28522 [Translation] Added support for multiple files or directories in XliffLintCommand (yceruto)
This PR was squashed before being merged into the 4.2-dev branch (closes #28522). Discussion ---------- [Translation] Added support for multiple files or directories in XliffLintCommand | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#10368 Same approach of symfony/symfony#28521 Commits ------- 88ec37bed7 [Translation] Added support for multiple files or directories in XliffLintCommand
2 parents 792f8a8 + 2559b35 commit 2bc884f

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* deprecated `TranslatorInterface` in favor of `Symfony\Contracts\Translation\TranslatorInterface`
99
* deprecated `MessageSelector`, `Interval` and `PluralizationRules`; use `IdentityTranslator` instead
1010
* Added `IntlMessageFormatter` and `FallbackMessageFormatter`
11+
* added support for multiple files and directories in `XliffLintCommand`
1112

1213
4.1.0
1314
-----

Command/XliffLintCommand.php

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

1414
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Exception\RuntimeException;
16+
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
@@ -52,7 +53,7 @@ protected function configure()
5253
{
5354
$this
5455
->setDescription('Lints a XLIFF file and outputs encountered errors')
55-
->addArgument('filename', null, 'A file or a directory or STDIN')
56+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
5657
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5758
->setHelp(<<<EOF
5859
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
@@ -79,25 +80,27 @@ protected function configure()
7980
protected function execute(InputInterface $input, OutputInterface $output)
8081
{
8182
$io = new SymfonyStyle($input, $output);
82-
$filename = $input->getArgument('filename');
83+
$filenames = (array) $input->getArgument('filename');
8384
$this->format = $input->getOption('format');
8485
$this->displayCorrectFiles = $output->isVerbose();
8586

86-
if (!$filename) {
87+
if (0 === \count($filenames)) {
8788
if (!$stdin = $this->getStdin()) {
8889
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
8990
}
9091

9192
return $this->display($io, array($this->validate($stdin)));
9293
}
9394

94-
if (!$this->isReadable($filename)) {
95-
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
96-
}
97-
9895
$filesInfo = array();
99-
foreach ($this->getFiles($filename) as $file) {
100-
$filesInfo[] = $this->validate(file_get_contents($file), $file);
96+
foreach ($filenames as $filename) {
97+
if (!$this->isReadable($filename)) {
98+
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
99+
}
100+
101+
foreach ($this->getFiles($filename) as $file) {
102+
$filesInfo[] = $this->validate(file_get_contents($file), $file);
103+
}
101104
}
102105

103106
return $this->display($io, $filesInfo);

Tests/Command/XliffLintCommandTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ public function testLintCorrectFile()
4040
$this->assertContains('OK', trim($tester->getDisplay()));
4141
}
4242

43+
public function testLintCorrectFiles()
44+
{
45+
$tester = $this->createCommandTester();
46+
$filename1 = $this->createFile();
47+
$filename2 = $this->createFile();
48+
49+
$tester->execute(
50+
array('filename' => array($filename1, $filename2)),
51+
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
52+
);
53+
54+
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
55+
$this->assertContains('OK', trim($tester->getDisplay()));
56+
}
57+
4358
/**
4459
* @dataProvider provideStrictFilenames
4560
*/

0 commit comments

Comments
 (0)