From 991c552a46ba8768ed37f5f2035515655f779678 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 25 Oct 2022 13:11:38 +0200 Subject: [PATCH] Improve text for asking questions/errors --- src/EntityBuilder/AbstractEntityCommand.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/EntityBuilder/AbstractEntityCommand.php b/src/EntityBuilder/AbstractEntityCommand.php index cb33fb6..406103c 100644 --- a/src/EntityBuilder/AbstractEntityCommand.php +++ b/src/EntityBuilder/AbstractEntityCommand.php @@ -52,13 +52,14 @@ abstract class AbstractEntityCommand extends Command $builder->setAll($entity); $this->em->persist($entity); - if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create "%s" with above properties', $entity)))) { + if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to create "%s" with above properties?', $entity)))) { $io->success(sprintf('Object "%s" stored successfully', $entity)); } } while ($io->askQuestion(new ConfirmationQuestion('Create another entity?', false))); } elseif ($input->getOption('modify')) { $io->info(sprintf('Modifying "%s"', $this->getEntityClass())); $entity = $this->select($io, $id); + do { $builder->setByQuestion($entity); } while ($io->askQuestion(new ConfirmationQuestion('Modify another property?'))); @@ -66,7 +67,8 @@ abstract class AbstractEntityCommand extends Command } elseif ($input->getOption('delete')) { $io->info(sprintf('Deleting "%s"', $this->getEntityClass())); $entity = $this->select($io, $id); - if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to delete %s', $entity)))) { + + if ($io->askQuestion(new ConfirmationQuestion(sprintf('Are you sure you want to delete %s?', $entity)))) { $name = (string)$entity; $this->em->remove($entity); $io->success(sprintf('Config "%s" deleted', $name)); @@ -74,6 +76,7 @@ abstract class AbstractEntityCommand extends Command } elseif ($input->getOption('show')) { $io->info(sprintf('Showing "%s"', $this->getEntityClass())); $entity = $this->select($io, $id); + $table = $io->createTable(); $table->setHeaders(['property', 'value']); $table->setRows($builder->getAllPropertiesTable($entity)); @@ -82,13 +85,14 @@ abstract class AbstractEntityCommand extends Command } elseif ($input->getOption('all')) { $io->info(sprintf('Showing all %s', $this->getEntityClass())); $entities = $this->em->getRepository($this->getEntityClass())->findAll(); + $table = $io->createTable(); $table->setHeaders($builder->getPopertyNames()); $table->setRows(array_map(fn(object $o) => $builder->getAllProperties($o), $entities)); $table->setHeaderTitle($this->getEntityClass()); $table->render(); } else { - $io->error('Select at least one of the options: Create (-c), Modify (-m), Delete (-d) or Show (-s)'); + $io->error('Select one of the options: Create (-c), Modify (-m), Delete (-d), Show (-s) or All (-a)'); return Command::INVALID; } @@ -111,7 +115,7 @@ abstract class AbstractEntityCommand extends Command if (empty($entities)) { throw new Exception('No objects found'); } - $question = new ChoiceQuestion('Select configuration to delete', $entities); - return $io->askQuestion($question); + + return $io->askQuestion(new ChoiceQuestion('Select the object', $entities)); } } \ No newline at end of file