Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0f7950

Browse files
ycerutonicolas-grekas
authored andcommitted
[Yaml] Added support for multiple files or directories in LintCommand
1 parent00e5cd9 commitd0f7950

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

‎src/Symfony/Component/Yaml/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* added support for multiple files or directories in`LintCommand`
8+
49
4.0.0
510
-----
611

‎src/Symfony/Component/Yaml/Command/LintCommand.php‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useSymfony\Component\Console\Command\Command;
1515
useSymfony\Component\Console\Exception\InvalidArgumentException;
1616
useSymfony\Component\Console\Exception\RuntimeException;
17+
useSymfony\Component\Console\Input\InputArgument;
1718
useSymfony\Component\Console\Input\InputInterface;
1819
useSymfony\Component\Console\Input\InputOption;
1920
useSymfony\Component\Console\Output\OutputInterface;
@@ -53,7 +54,7 @@ protected function configure()
5354
{
5455
$this
5556
->setDescription('Lints a file and outputs encountered errors')
56-
->addArgument('filename',null,'A file or a directory or STDIN')
57+
->addArgument('filename',InputArgument::IS_ARRAY,'A file or a directory or STDIN')
5758
->addOption('format',null, InputOption::VALUE_REQUIRED,'The output format','txt')
5859
->addOption('parse-tags',null, InputOption::VALUE_NONE,'Parse custom tags')
5960
->setHelp(<<<EOF
@@ -81,26 +82,28 @@ protected function configure()
8182
protectedfunctionexecute(InputInterface$input,OutputInterface$output)
8283
{
8384
$io =newSymfonyStyle($input,$output);
84-
$filename =$input->getArgument('filename');
85+
$filenames = (array)$input->getArgument('filename');
8586
$this->format =$input->getOption('format');
8687
$this->displayCorrectFiles =$output->isVerbose();
8788
$flags =$input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS :0;
8889

89-
if (!$filename) {
90+
if (0 ===\count($filenames)) {
9091
if (!$stdin =$this->getStdin()) {
9192
thrownewRuntimeException('Please provide a filename or pipe file content to STDIN.');
9293
}
9394

9495
return$this->display($io,array($this->validate($stdin,$flags)));
9596
}
9697

97-
if (!$this->isReadable($filename)) {
98-
thrownewRuntimeException(sprintf('File or directory "%s" is not readable.',$filename));
99-
}
100-
10198
$filesInfo =array();
102-
foreach ($this->getFiles($filename)as$file) {
103-
$filesInfo[] =$this->validate(file_get_contents($file),$flags,$file);
99+
foreach ($filenamesas$filename) {
100+
if (!$this->isReadable($filename)) {
101+
thrownewRuntimeException(sprintf('File or directory "%s" is not readable.',$filename));
102+
}
103+
104+
foreach ($this->getFiles($filename)as$file) {
105+
$filesInfo[] =$this->validate(file_get_contents($file),$flags,$file);
106+
}
104107
}
105108

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public function testLintCorrectFile()
3737
$this->assertRegExp('/^\/\/ OK in /',trim($tester->getDisplay()));
3838
}
3939

40+
publicfunctiontestLintCorrectFiles()
41+
{
42+
$tester =$this->createCommandTester();
43+
$filename1 =$this->createFile('foo: bar');
44+
$filename2 =$this->createFile('bar: baz');
45+
46+
$ret =$tester->execute(array('filename' =>array($filename1,$filename2)),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
47+
48+
$this->assertEquals(0,$ret,'Returns 0 in case of success');
49+
$this->assertRegExp('/^\/\/ OK in /',trim($tester->getDisplay()));
50+
}
51+
4052
publicfunctiontestLintIncorrectFile()
4153
{
4254
$incorrectContent ='

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp