[Translation] Added support for multiple files or directories in XliffLintCommand
This commit is contained in:
parent
00e5cd9a1c
commit
88ec37bed7
@ -8,6 +8,7 @@ CHANGELOG
|
||||
* deprecated `TranslatorInterface` in favor of `Symfony\Contracts\Translation\TranslatorInterface`
|
||||
* deprecated `MessageSelector`, `Interval` and `PluralizationRules`; use `IdentityTranslator` instead
|
||||
* Added `IntlMessageFormatter` and `FallbackMessageFormatter`
|
||||
* added support for multiple files and directories in `XliffLintCommand`
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Translation\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@ -52,7 +53,7 @@ class XliffLintCommand extends Command
|
||||
{
|
||||
$this
|
||||
->setDescription('Lints a XLIFF file and outputs encountered errors')
|
||||
->addArgument('filename', null, 'A file or a directory or STDIN')
|
||||
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
|
||||
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
|
||||
->setHelp(<<<EOF
|
||||
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
|
||||
@ -79,11 +80,11 @@ EOF
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$filename = $input->getArgument('filename');
|
||||
$filenames = (array) $input->getArgument('filename');
|
||||
$this->format = $input->getOption('format');
|
||||
$this->displayCorrectFiles = $output->isVerbose();
|
||||
|
||||
if (!$filename) {
|
||||
if (0 === \count($filenames)) {
|
||||
if (!$stdin = $this->getStdin()) {
|
||||
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||
}
|
||||
@ -91,13 +92,15 @@ EOF
|
||||
return $this->display($io, array($this->validate($stdin)));
|
||||
}
|
||||
|
||||
if (!$this->isReadable($filename)) {
|
||||
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
|
||||
}
|
||||
|
||||
$filesInfo = array();
|
||||
foreach ($this->getFiles($filename) as $file) {
|
||||
$filesInfo[] = $this->validate(file_get_contents($file), $file);
|
||||
foreach ($filenames as $filename) {
|
||||
if (!$this->isReadable($filename)) {
|
||||
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
|
||||
}
|
||||
|
||||
foreach ($this->getFiles($filename) as $file) {
|
||||
$filesInfo[] = $this->validate(file_get_contents($file), $file);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->display($io, $filesInfo);
|
||||
|
@ -40,6 +40,21 @@ class XliffLintCommandTest extends TestCase
|
||||
$this->assertContains('OK', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
public function testLintCorrectFiles()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$filename1 = $this->createFile();
|
||||
$filename2 = $this->createFile();
|
||||
|
||||
$tester->execute(
|
||||
array('filename' => array($filename1, $filename2)),
|
||||
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
|
||||
$this->assertContains('OK', trim($tester->getDisplay()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideStrictFilenames
|
||||
*/
|
||||
|
Reference in New Issue
Block a user