Skip to content

Commit 09a3ce6

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 ------- 7b262d8c29 [FrameworkBundle] Use getErrorStyle() when relevant 9a3a5686c8 Use stderr for some other commands 1ee48bfd60 [FrameworkBundle] Make use of stderr for non reliable output
2 parents 2254638 + 6430d55 commit 09a3ce6

6 files changed

+30
-25
lines changed

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
}

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
}

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
}

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
}

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
}

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)

0 commit comments

Comments
 (0)