Skip to content

Commit

Permalink
Use error style for notifications
Browse files Browse the repository at this point in the history
stderr is not a great name for something that is not meant to be
processed (piped into) a program, but to be read by humans.
Most commands should use stderr, and some of them should partially use
stdout, typically when dumping SQL requests.
  • Loading branch information
greg0ire committed Oct 22, 2022
1 parent be835bb commit e96a274
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 34 deletions.
Expand Up @@ -67,7 +67,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$ownerClass = $input->getArgument('owner-class');
Expand Down
Expand Up @@ -66,7 +66,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$entityClass = $input->getArgument('entity-class');
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$cacheDriver = $em->getConfiguration()->getMetadataCache();
Expand Down
Expand Up @@ -63,7 +63,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getQueryCache();
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$name = $input->getArgument('region-name');
Expand Down
Expand Up @@ -65,7 +65,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getResultCache();
Expand Down
Expand Up @@ -97,7 +97,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');
$ui->getErrorStyle()->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');

// Process source directories
$fromPaths = array_merge([$input->getArgument('from-path')], $input->getOption('from'));
Expand Down
Expand Up @@ -88,7 +88,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');
$ui->getErrorStyle()->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');

$em = $this->getEntityManager($input);

Expand Down
Expand Up @@ -38,7 +38,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$ui->warning('This console command has been deprecated and will be removed in a future version of Doctrine ORM.');

$em = $this->getEntityManager($input);
Expand Down
Expand Up @@ -76,7 +76,7 @@ class is supposed to extend which. You have to adjust the entity
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');

$em = $this->getEntityManager($input);
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);

Expand Down
Expand Up @@ -48,7 +48,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.');

$em = $this->getEntityManager($input);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php
Expand Up @@ -43,7 +43,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$entityManager = $this->getEntityManager($input);

Expand Down
Expand Up @@ -62,7 +62,7 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$entityManager = $this->getEntityManager($input);

Expand Down
Expand Up @@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$metadatas = $em->getMetadataFactory()->getAllMetadata();

if (empty($metadatas)) {
$ui->success('No Metadata Classes to process.');
$ui->getErrorStyle()->success('No Metadata Classes to process.');

return 0;
}
Expand Down
Expand Up @@ -57,14 +57,16 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
return 0;
}

$ui->caution('This operation should not be executed in a production environment!');
$notificationUi = $ui->getErrorStyle();

$ui->text('Creating database schema...');
$ui->newLine();
$notificationUi->caution('This operation should not be executed in a production environment!');

$notificationUi->text('Creating database schema...');
$notificationUi->newLine();

$schemaTool->createSchema($metadatas);

$ui->success('Database schema created successfully!');
$notificationUi->success('Database schema created successfully!');

return 0;
}
Expand Down
Expand Up @@ -67,22 +67,24 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
return 0;
}

$notificationUi = $ui->getErrorStyle();

if ($force) {
$ui->text('Dropping database schema...');
$ui->newLine();
$notificationUi->text('Dropping database schema...');
$notificationUi->newLine();

if ($isFullDatabaseDrop) {
$schemaTool->dropDatabase();
} else {
$schemaTool->dropSchema($metadatas);
}

$ui->success('Database schema dropped successfully!');
$notificationUi->success('Database schema dropped successfully!');

return 0;
}

$ui->caution('This operation should not be executed in a production environment!');
$notificationUi->caution('This operation should not be executed in a production environment!');

if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
Expand All @@ -91,12 +93,12 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
}

if (empty($sqls)) {
$ui->success('Nothing to drop. The database is empty!');
$notificationUi->success('Nothing to drop. The database is empty!');

return 0;
}

$ui->text(
$notificationUi->text(
[
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)),
'',
Expand Down
Expand Up @@ -78,8 +78,10 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $

$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);

$notificationUi = $ui->getErrorStyle();

if (empty($sqls)) {
$ui->success('Nothing to update - your database is already in sync with the current entity metadata.');
$notificationUi->success('Nothing to update - your database is already in sync with the current entity metadata.');

return 0;
}
Expand All @@ -95,25 +97,25 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $

if ($force) {
if ($dumpSql) {
$ui->newLine();
$notificationUi->newLine();
}

$ui->text('Updating database schema...');
$ui->newLine();
$notificationUi->text('Updating database schema...');
$notificationUi->newLine();

$schemaTool->updateSchema($metadatas, $saveMode);

$pluralization = count($sqls) === 1 ? 'query was' : 'queries were';

$ui->text(sprintf(' <info>%s</info> %s executed', count($sqls), $pluralization));
$ui->success('Database schema updated successfully!');
$notificationUi->text(sprintf(' <info>%s</info> %s executed', count($sqls), $pluralization));
$notificationUi->success('Database schema updated successfully!');
}

if ($dumpSql || $force) {
return 0;
}

$ui->caution(
$notificationUi->caution(
[
'This operation should not be executed in a production environment!',
'',
Expand All @@ -122,7 +124,7 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
]
);

$ui->text(
$notificationUi->text(
[
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)),
'',
Expand Down
Expand Up @@ -40,7 +40,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = new SymfonyStyle($input, $output);
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$validator = new SchemaValidator($em);
Expand Down

0 comments on commit e96a274

Please sign in to comment.