Skip to content

Commit

Permalink
minor #15991 Updated the stlyes of the YAML commands (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.8 branch (closes #15991).

Discussion
----------

Updated the stlyes of the YAML commands

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

![yaml_1](https://cloud.githubusercontent.com/assets/73419/10158656/dfedd2ec-6693-11e5-8691-304b5dd19edc.png)

![yaml_2](https://cloud.githubusercontent.com/assets/73419/10158658/e22e1bfc-6693-11e5-9626-38f21ffb5a9a.png)

Commits
-------

c3ce7ca Updated the stlyes of the YAML commands
  • Loading branch information
fabpot committed Oct 2, 2015
2 parents 1e0adf4 + c3ce7ca commit 112c66c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 18 additions & 11 deletions src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
Expand Down Expand Up @@ -62,8 +63,10 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$stdout = $output;
$output = new SymfonyStyle($input, $output);
if (false !== strpos($input->getFirstArgument(), ':l')) {
$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>');
$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.');
}

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

return $this->display($input, $output, array($this->validate($content)));
return $this->display($input, $stdout, $output, array($this->validate($content)));
}

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

return $this->display($input, $output, $filesInfo);
return $this->display($input, $stdout, $output, $filesInfo);
}

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

private function display(InputInterface $input, OutputInterface $output, $files)
private function display(InputInterface $input, OutputInterface $stdout, $output, $files)
{
switch ($input->getOption('format')) {
case 'txt':
return $this->displayTxt($output, $files);
return $this->displayTxt($stdout, $output, $files);
case 'json':
return $this->displayJson($output, $files);
default:
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
}
}

private function displayTxt(OutputInterface $output, $filesInfo)
private function displayTxt(OutputInterface $stdout, $output, $filesInfo)
{
$errors = 0;

foreach ($filesInfo as $info) {
if ($info['valid'] && $output->isVerbose()) {
$output->writeln('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
if ($info['valid'] && $stdout->isVerbose()) {
$output->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
} elseif (!$info['valid']) {
++$errors;
$output->writeln(sprintf('<error>KO</error> in %s', $info['file']));
$output->writeln(sprintf('<error>>> %s</error>', $info['message']));
$output->text(sprintf('<error> ERROR </error> in %s', $info['file']));
$output->text(sprintf('<error> >> %s</error>', $info['message']));
}
}

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

return min($errors, 1);
}
Expand Down
Expand Up @@ -25,8 +25,7 @@ public function testDebugAllRoutes()
$ret = $tester->execute(array('name' => null), array('decorated' => false));

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

public function testDebugSingleRoute()
Expand Down

0 comments on commit 112c66c

Please sign in to comment.