8000 merged branch hason/return_code (PR #5586) · Ouark/symfony@98070d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98070d5

Browse files
committed
merged branch hason/return_code (PR symfony#5586)
This PR was squashed before being merged into the 2.1 branch (closes symfony#5586). Commits ------- 6b66bc3 [2.1] Added missing error return codes in commands Discussion ---------- [2.1] Added missing error return codes in commands Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes License of the code: MIT See: symfony#5585 --------------------------------------------------------------------------- by fabpot at 2012-09-24T12:10:47Z Exit code values are standardized and some values have some well-defined meaning. Have a look here for more info: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L67
2 parents 77a6eb6 + 6b66bc3 commit 98070d5

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484

8585
if (!$matches) {
8686
$output->writeln('<fg=red>None of the routes matches</>');
87+
88+
return 1;
8789
}
8890
}
8991
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
*/
2727
class TranslationUpdateCommand extends ContainerAwareCommand
2828
{
29+
const RETURN_CODE_MISSING_OPTIONS = 1;
30+
31+
const RETURN_CODE_UNSUPPORTED_FORMAT = 2;
32+
2933
/**
3034
* Compiled catalogue of messages.
3135
* @var MessageCatalogue
@@ -82,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8286
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
8387
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
8488

85-
return;
89+
return self::RETURN_CODE_MISSING_OPTIONS;
8690
}
8791

8892
// check format
@@ -92,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9296
$output->writeln('<error>Wrong output format</error>');
9397
$output->writeln('Supported formats are '.implode(', ', $supportedFormats).'.');
9498

95-
return;
99+
return self::RETURN_CODE_UNSUPPORTED_FORMAT;
96100
}
97101

98102
// get bundle directory

src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
} catch (SchemaException $e) {
6363
$output->writeln("Aborting: " . $e->getMessage());
6464

65-
return;
65+
return 1;
6666
}
6767

6868
foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {

src/Symfony/Bundle/TwigBundle/Command/LintCommand.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
$template .= fread(STDIN, 1024);
7171
}
7272

73-
return $twig->parse($twig->tokenize($template));
73+
return $this->validateTemplate($twig, $output, $template);
7474
}
7575

7676
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -87,26 +87,39 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$files = Finder::create()->files()->in($dir)->name('*.twig');
8888
}
8989

90-
$error = false;
90+
$errors = 0;
9191
foreach ($files as $file) {
92-
try {
93-
$twig->parse($twig->tokenize(file_get_contents($file), (string) $file));
94-
$output->writeln(sprintf("<info>OK</info> in %s", $file));
95-
} catch (\Twig_Error $e) {
96-
$this->renderException($output, $file, $e);
97-
$error = true;
98-
}
92+
$errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file);
93+
}
94+
95+
return $errors > 0 ? 1 : 0;
96+
}
97+
98+
protected function validateTemplate(\Twig_Environment $twig, OutputInterface $output, $template, $file = null)
99+
{
100+
try {
101+
$twig->parse($twig->tokenize($template, $file ? (string) $file : null));
102+
$output->writeln('<info>OK</info>'.($file ? sprintf(' in %s', $file) : ''));
103+
} catch (\Twig_Error $e) {
104+
$this->renderException($output, $template, $e, $file);
105+
106+
return 1;
99107
}
100108

101-
return $error ? 1 : 0;
109+
return 0;
102110
}
103111

104-
protected function renderException(OutputInterface $output, $file, \Twig_Error $exception)
112+
protected function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
105113
{
106114
$line = $exception->getTemplateLine();
107-
$lines = $this->getContext($file, $line);
115+
$lines = $this->getContext($template, $line);
116+
117+
if ($file) {
118+
$output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
119+
} else {
120+
$output->writeln(sprintf("<error>KO</error> (line %s)", $line));
121+
}
108122

109-
$output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
110123
foreach ($lines as $no => $code) {
111124
$output->writeln(sprintf(
112125
"%s %-6s %s",
@@ -120,10 +133,9 @@ protected function renderException(OutputInterface $output, $file, \Twig_Error $
120133
}
121134
}
122135

123-
protected function getContext($file, $line, $context = 3)
136+
protected function getContext($template, $line, $context = 3)
124137
{
125-
$fileContent = file_get_contents($file);
126-
$lines = explode("\n", $fileContent);
138+
$lines = explode("\n", $template);
127139

128140
$position = max(0, $line - $context);
129141
$max = min(count($lines), $line - 1 + $context);

0 commit comments

Comments
 (0)
0