10000 Updated the stlyes of the YAML commands · wouterj/symfony@c3ce7ca · GitHub
[go: up one dir, main page]

Skip to content

Commit c3ce7ca

Browse files
javiereguiluzfabpot
authored andcommitted
Updated the stlyes of the YAML commands
1 parent b630972 commit c3ce7ca

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
1819
use Symfony\Component\Finder\Finder;
1920
use Symfony\Component\Yaml\Exception\ParseException;
2021
use Symfony\Component\Yaml\Parser;
@@ -62,8 +63,10 @@ protected function configure()
6263

6364
protected function execute(InputInterface $input, OutputInterface $output)
6465
{
66+
$stdout = $output;
67+
$output = new SymfonyStyle($input, $output);
6568
if (false !== strpos($input->getFirstArgument(), ':l')) {
66-
$output->writeln('<comment>The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.</comment>');
69+
$output->caution('The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.');
6770
}
6871

6972
$filename = $input->getArgument('filename');
@@ -78,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7881
$content .= fread(STDIN, 1024);
7982
}
8083

81-
return $this->display($input, $output, array($this->validate($content)));
84+
return $this->display($input, $stdout, $output, array($this->validate($content)));
8285
}
8386

8487
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -100,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
100103
$filesInfo[] = $this->validate(file_get_contents($file), $file);
101104
}
102105

103-
return $this->display($input, $output, $filesInfo);
106+
return $this->display($input, $stdout, $output, $filesInfo);
104107
}
105108

106109
private function validate($content, $file = null)
@@ -115,33 +118,37 @@ private function validate($content, $file = null)
115118
return array('file' => $file, 'valid' => true);
116119
}
117120

118-
private function display(InputInterface $input, OutputInterface $output, $files)
121+
private function display(InputInterface $input, OutputInterface $stdout, $output, $files)
119122
{
120123
switch ($input->getOption('format')) {
121124
case 'txt':
122-
return $this->displayTxt($output, $files);
125+
return $this->displayTxt($stdout, $output, $files);
123126
case 'json':
124127
return $this->displayJson($output, $files);
125128
default:
126129
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
127130
}
128131
}
129132

130-
private function displayTxt(OutputInterface $output, $filesInfo)
133+
private function displayTxt(OutputInterface $stdout, $output, $filesInfo)
131134
{
132135
$errors = 0;
133136

134137
foreach ($filesInfo as $info) {
135-
if ($info['valid'] && $output->isVerbose()) {
136-
$output->writeln('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
138+
if ($info['valid'] && $stdout->isVerbose()) {
139+
$output->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
137140
} elseif (!$info['valid']) {
138141
++$errors;
139-
$output->writeln(sprintf('<error>KO</error> in %s', $info['file']));
140-
$output->writeln(sprintf('<error>>> %s</error>', $info['message']));
142+
$output->text(sprintf('<error> ERROR </error> in %s', $info['file']));
143+
$output->text(sprintf('<error> >> %s</error>', $info['message']));
141144
}
142145
}
143146

144-
$output->writeln(sprintf('<comment>%d/%d valid files</comment>', count($filesInfo) - $errors, count($filesInfo)));
147+
if ($errors === 0) {
148+
$output->success(sprintf('All %d YAML files contain valid syntax.', count($filesInfo)));
149+
} else {
150+
$output->warning(sprintf('%d YAML files have valid syntax and %d contain errors.', count($filesInfo) - $errors, $errors));
151+
}
145152

146153
return min($errors, 1);
147154
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public function testDebugAllRoutes()
2525
$ret = $tester->execute(array('name' => null), array('decorated' => false));
2626

2727
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
28-
$this->assertContains('Path', $tester->getDisplay());
29-
$this->assertContains('/foo', $tester->getDisplay());
28+
$this->assertContains('Name Method Scheme Host Path', $tester->getDisplay());
3029
}
3130

3231
public function testDebugSingleRoute()

0 commit comments

Comments
 (0)
0