8000 feature #20632 [FrameworkBundle] Make use of stderr for non reliable … · symfony/symfony@4abd0c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4abd0c6

Browse files
committed
feature #20632 [FrameworkBundle] Make use of stderr for non reliable output (chalasr, ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Make use of stderr for non reliable output | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Built-in commands should make use of the proper outputs. As a feature on master, considering that people may actually rely on stdout and the fact commands have been changed a lot since 2.7, I think it's not worth doing this change on lower branches. Please see also #20586 which adds a `SymfonyStyle::getErrorStyle()` shortcut for easily switching to stderr. Commits ------- 7b262d8 [FrameworkBundle] Use getErrorStyle() when relevant 9a3a568 Use stderr for some other commands 1ee48bf [FrameworkBundle] Make use of stderr for non reliable output
2 parents a399e75 + 7b262d8 commit 4abd0c6

13 files changed

+50
-44
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$twig = $this->getTwigEnvironment();
8888

8989
if (null === $twig) {
90-
$io->error('The Twig environment needs to be set.');
91-
92-
return 1;
90+
throw new \RuntimeException('The Twig environment needs to be set.');
9391
}
9492

9593
$types = array('functions', 'filters', 'tests', 'globals');

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8888
$io = new SymfonyStyle($input, $output);
8989

9090
if (null === $twig = $this->getTwigEnvironment()) {
91-
$io->error('The Twig environment needs to be set.');
92-
93-
return 1;
91+
throw new \RuntimeException('The Twig environment needs to be set.');
9492
}
9593

9694
$filenames = $input->getArgument('filename');

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ protected function configure()
6262
protected function execute(InputInterface $input, OutputInterface $output)
6363
{
6464
$io = new SymfonyStyle($input, $output);
65+
$errorIo = $io->getErrorStyle();
6566

6667
if (null === $name = $input->getArgument('name')) {
67-
$this->listBundles($io);
68-
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
69-
$io->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
68+
$this->listBundles($errorIo);
69+
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
70+
$errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
7071

7172
return;
7273
}
@@ -98,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9899
try {
99100
$config = $this->getConfigForPath($config, $path, $extensionAlias);
100101
} catch (LogicException $e) {
101-
$io->error($e->getMessage());
102+
$errorIo->error($e->getMessage());
102103

103104
return;
104105
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function configure()
5555
When the option is not provided, <comment>yaml</comment> is used.
5656
5757
<info>php %command.full_name% FrameworkBundle --format=xml</info>
58-
58+
5959
For dumping a specific option, add its path as second argument (only available for the yaml format):
6060
6161
<info>php %command.full_name% framework profiler.matcher</info>
@@ -73,10 +73,11 @@ protected function configure()
7373
protected function execute(InputInterface $input, OutputInterface $output)
7474
{
7575
$io = new SymfonyStyle($input, $output);
76+
$errorIo = $io->getErrorStyle();
7677

7778
if (null === $name = $input->getArgument('name')) {
78-
$this->listBundles($io);
79-
$io->comment(array(
79+
$this->listBundles($errorIo);
80+
$errorIo->comment(array(
8081
'Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. <comment>config:dump-reference FrameworkBundle</comment>)',
8182
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
8283
));
@@ -94,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9495
$path = $input->getArgument('path');
9596

9697
if ($path !== null && 'yaml' !== $format) {
97-
$io->error('The "path" option is only available for the "yaml" format.');
98+
$errorIo->error('The "path" option is only available for the "yaml" format.');
9899

99100
return 1;
100101
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ protected function configure()
9494
protected function execute(InputInterface $input, OutputInterface $output)
9595
{
9696
$io = new SymfonyStyle($input, $output);
97+
$errorIo = $io->getErrorStyle();
98+
9799
$this->validateInput($input);
98100
$object = $this->getContainerBuilder();
99101

@@ -111,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
111113
} elseif ($tag = $input->getOption('tag')) {
112114
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
113115
} elseif ($name = $input->getArgument('name')) {
114-
$name = $this->findProperServiceName($input, $io, $object, $name);
116+
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
115117
$options = array('id' => $name);
116118
} else {
117119
$options = array('show_private' => $input->getOption('show-private'));
@@ -122,15 +124,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
122124
$options['show_arguments'] = $input->getOption('show-arguments');
123125
$options['raw_text'] = $input->getOption('raw');
124126
$options['output'] = $io;
125-
$helper->describe($output, $object, $options);
127+
$helper->describe($io, $object, $options);
126128

127129
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
128130
if ($input->getOption('tags')) {
129-
$io->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
131+
$errorIo->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
130132
} elseif ($input->getOption('parameters')) {
131-
$io->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
133+
$errorIo->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
132134
} else {
133-
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
135+
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
134136
}
135137
}
136138
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6565
$options = array();
6666
if ($event = $input->getArgument('event')) {
6767
if (!$dispatcher->hasListeners($event)) {
68-
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
68+
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
6969

7070
return;
7171
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
159159
$outputMessage .= sprintf(' and domain "%s"', $domain);
160160
}
161161

162-
$io->warning($outputMessage);
162+
$io->getErrorStyle()->warning($outputMessage);
163163

164164
return;
165165
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ public function isEnabled()
8585
protected function execute(InputInterface $input, OutputInterface $output)
8686
{
8787
$io = new SymfonyStyle($input, $output);
88+
$errorIo = $io->getErrorStyle();
8889

8990
// check presence of force or dump-message
9091
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
91-
$io->error('You must choose one of --force or --dump-messages');
92+
$errorIo->error('You must choose one of --force or --dump-messages');
9293

9394
return 1;
9495
}
@@ -97,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9798
$writer = $this->getContainer()->get('translation.writer');
9899
$supportedFormats = $writer->getFormats();
99100
if (!in_array($input->getOption('output-format'), $supportedFormats)) {
100-
$io->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.'));
101+
$errorIo->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.'));
101102

102103
return 1;
103104
}
@@ -127,12 +128,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
127128
}
128129
}
129130

130-
$io->title('Translation Messages Extractor and Dumper');
131-
$io->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
131+
$errorIo->title('Translation Messages Extractor and Dumper');
132+
$errorIo->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
132133

133134
// load any messages from templates
134135
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
135-
$io->comment('Parsing templates...');
136+
$errorIo->comment('Parsing templates...');
136137
$extractor = $this->getContainer()->get('translation.extractor');
137138
$extractor->setPrefix($input->getOption('no-prefix') ? '' : $input->getOption('prefix'));
138139
foreach ($transPaths as $path) {
@@ -144,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144145

145146
// load any existing messages from the translation files
146147
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
147-
$io->comment('Loading translation files...');
148+
$errorIo->comment('Loading translation files...');
148149
$loader = $this->getContainer()->get('translation.loader');
149150
foreach ($transPaths as $path) {
150151
$path .= 'translations';
@@ -165,7 +166,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
165166

166167
// Exit if no messages found.
167168
if (!count($operation->getDomains())) {
168-
$io->warning('No translation messages were found.');
169+
$errorIo->warning('No translation messages were found.');
169170

170171
return;
171172
}
@@ -199,7 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199200
}
200201

201202
if ($input->getOption('output-format') == 'xlf') {
202-
$io->comment('Xliff output version is <info>1.2</info>');
203+
$errorIo->comment('Xliff output version is <info>1.2</info>');
203204
}
204205

205206
$resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was');
@@ -211,7 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
211212

212213
// save the files
213214
if ($input->getOption('force') === true) {
214-
$io->comment('Writing files...');
215+
$errorIo->comment('Writing files...');
215216

216217
$bundleTransPath = false;
217218
foreach ($transPaths as $path) {
@@ -232,7 +233,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
232233
}
233234
}
234235

235-
$io->success($resultMessage.'.');
236+
$errorIo->success($resultMessage.'.');
236237
}
237238

238239
private function filterCatalogue(MessageCatalogue $catalogue, $domain)

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Symfony\Component\Console\Question\Question;
2021
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -114,8 +115,9 @@ protected function configure()
114115
protected function execute(InputInterface $input, OutputInterface $output)
115116
{
116117
$io = new SymfonyStyle($input, $output);
118+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
117119

118-
$input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine();
120+
$input->isInteractive() ? $errorIo->title('Symfony Password Encoder Utility') : $errorIo->newLine();
119121

120122
$password = $input->getArgument('password');
121123
$userClass = $this->getUserClass($input, $io);
@@ -131,22 +133,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
131133

132134
if (!$password) {
133135
if (!$input->isInteractive()) {
134-
$io->error('The password must not be empty.');
136+
$errorIo->error('The password must not be empty.');
135137

136138
return 1;
137139
}
138140
$passwordQuestion = $this->createPasswordQuestion();
139-
$password = $io->askQuestion($passwordQuestion);
141+
$password = $errorIo->askQuestion($passwordQuestion);
140142
}
141143

142144
$salt = null;
143145

144146
if ($input->isInteractive() && !$emptySalt) {
145147
$emptySalt = true;
146148

147-
$io->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
149+
$errorIo->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
148150

149-
if ($io->confirm('Confirm salt generation ?')) {
151+
if ($errorIo->confirm('Confirm salt generation ?')) {
150152
$salt = $this->generateSalt();
151153
$emptySalt = false;
152154
}
@@ -166,12 +168,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
166168
$io->table(array('Key', 'Value'), $rows);
167169

168170
if (!$emptySalt) {
169-
$io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
171+
$errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
170172
} elseif ($bcryptWithoutEmptySalt) {
171-
$io->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
173+
$errorIo->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
172174
}
173175

174-
$io->success('Password encoding succeeded');
176+
$errorIo->success('Password encoding succeeded');
175177
}
176178

177179
/**

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function configure()
8080
*/
8181
protected function execute(InputInterface $input, OutputInterface $output)
8282
{
83-
$io = new SymfonyStyle($input, $output);
83+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
8484

8585
if (null === $documentRoot = $input->getOption('docroot')) {
8686
if (!$this->documentRoot) {

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2021
use Symfony\Component\Console\Style\SymfonyStyle;
2122

2223
/**
@@ -79,7 +80,7 @@ protected function configure()
7980
*/
8081
protected function execute(InputInterface $input, OutputInterface $output)
8182
{
82-
$io = new SymfonyStyle($input, $cliOutput = $output);
83+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
8384

8485
if (!extension_loaded('pcntl')) {
8586
$io->error(array(
@@ -88,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8889
));
8990

9091
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
91-
return $this->getApplication()->find('server:run')->run($input, $cliOutput);
92+
return $this->getApplication()->find('server:run')->run($input, $output);
9293
}
9394

9495
return 1;

src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php

Lines changed: 2 additions & 1 deletion
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\Output\ConsoleOutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
/**
@@ -44,7 +45,7 @@ protected function configure()
4445
*/
4546
protected function execute(InputInterface $input, OutputInterface $output)
4647
{
47-
$io = new SymfonyStyle($input, $output);
48+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
4849
$server = new WebServer();
4950
if ($server->isRunning($input->getOption('pidfile'))) {
5051
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));

src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\WebServerBundle\WebServer;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

@@ -53,7 +54,7 @@ protected function configure()
5354
*/
5455
protected function execute(InputInterface $input, OutputInterface $output)
5556
{
56-
$io = new SymfonyStyle($input, $output);
57+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
5758

5859
try {
5960
$server = new WebServer();

0 commit comments

Comments
 (0)
0