From bac4de1a97e688b21f0925de26adb70504938072 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Mon, 28 Nov 2016 18:54:55 +0100 Subject: [PATCH] Use stderr for some other commands --- .../Command/TranslationDebugCommand.php | 4 +++- .../Command/TranslationUpdateCommand.php | 22 ++++++++++--------- .../Command/UserPasswordEncoderCommand.php | 18 ++++++++------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 299045d126b32..5bd23c5f5b964 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; @@ -159,7 +160,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $outputMessage .= sprintf(' and domain "%s"', $domain); } - $io->warning($outputMessage); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; + $errorIo->warning($outputMessage); return; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index c2083e034e32c..67ceac02eb0bf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Translation\Catalogue\TargetOperation; use Symfony\Component\Translation\Catalogue\MergeOperation; @@ -85,10 +86,11 @@ public function isEnabled() protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; // check presence of force or dump-message if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) { - $io->error('You must choose one of --force or --dump-messages'); + $errorIo->error('You must choose one of --force or --dump-messages'); return 1; } @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $writer = $this->getContainer()->get('translation.writer'); $supportedFormats = $writer->getFormats(); if (!in_array($input->getOption('output-format'), $supportedFormats)) { - $io->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.')); + $errorIo->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.')); return 1; } @@ -127,12 +129,12 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $io->title('Translation Messages Extractor and Dumper'); - $io->comment(sprintf('Generating "%s" translation files for "%s"', $input->getArgument('locale'), $currentName)); + $errorIo->title('Translation Messages Extractor and Dumper'); + $errorIo->comment(sprintf('Generating "%s" translation files for "%s"', $input->getArgument('locale'), $currentName)); // load any messages from templates $extractedCatalogue = new MessageCatalogue($input->getArgument('locale')); - $io->comment('Parsing templates...'); + $errorIo->comment('Parsing templates...'); $extractor = $this->getContainer()->get('translation.extractor'); $extractor->setPrefix($input->getOption('no-prefix') ? '' : $input->getOption('prefix')); foreach ($transPaths as $path) { @@ -144,7 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // load any existing messages from the translation files $currentCatalogue = new MessageCatalogue($input->getArgument('locale')); - $io->comment('Loading translation files...'); + $errorIo->comment('Loading translation files...'); $loader = $this->getContainer()->get('translation.loader'); foreach ($transPaths as $path) { $path .= 'translations'; @@ -165,7 +167,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Exit if no messages found. if (!count($operation->getDomains())) { - $io->warning('No translation messages were found.'); + $errorIo->warning('No translation messages were found.'); return; } @@ -199,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($input->getOption('output-format') == 'xlf') { - $io->comment('Xliff output version is 1.2'); + $errorIo->comment('Xliff output version is 1.2'); } $resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was'); @@ -211,7 +213,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // save the files if ($input->getOption('force') === true) { - $io->comment('Writing files...'); + $errorIo->comment('Writing files...'); $bundleTransPath = false; foreach ($transPaths as $path) { @@ -232,7 +234,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $io->success($resultMessage.'.'); + $errorIo->success($resultMessage.'.'); } private function filterCatalogue(MessageCatalogue $catalogue, $domain) diff --git a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php index 7151175d938e7..f9986ba9beba7 100644 --- a/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php +++ b/src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; @@ -85,8 +86,9 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); + $errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io; - $input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine(); + $input->isInteractive() ? $errorIo->title('Symfony Password Encoder Utility') : $errorIo->newLine(); $password = $input->getArgument('password'); $userClass = $input->getArgument('user-class'); @@ -101,12 +103,12 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$password) { if (!$input->isInteractive()) { - $io->error('The password must not be empty.'); + $errorIo->error('The password must not be empty.'); return 1; } $passwordQuestion = $this->createPasswordQuestion(); - $password = $io->askQuestion($passwordQuestion); + $password = $errorIo->askQuestion($passwordQuestion); } $salt = null; @@ -114,9 +116,9 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($input->isInteractive() && !$emptySalt) { $emptySalt = true; - $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.'); + $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.'); - if ($io->confirm('Confirm salt generation ?')) { + if ($errorIo->confirm('Confirm salt generation ?')) { $salt = $this->generateSalt(); $emptySalt = false; } @@ -136,12 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->table(array('Key', 'Value'), $rows); if (!$emptySalt) { - $io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt))); + $errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt))); } elseif ($bcryptWithoutEmptySalt) { - $io->note('Bcrypt encoder used: the encoder generated its own built-in salt.'); + $errorIo->note('Bcrypt encoder used: the encoder generated its own built-in salt.'); } - $io->success('Password encoding succeeded'); + $errorIo->success('Password encoding succeeded'); } /**