From 153f04ccd79be39693723a5b14ed66e6bc7fb4a7 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 24 Sep 2024 00:19:45 +0200 Subject: [PATCH] Make database name question more specific --- src/Console/BackupDatabaseCommand.php | 2 +- src/Console/CreateDatabaseCommand.php | 4 ++-- src/Console/CreatePermissionCommand.php | 11 ++++++++++ src/Console/DeleteDatabaseCommand.php | 2 +- src/Console/PurgeDatabaseCommand.php | 2 +- src/Console/RestoreDatabaseCommand.php | 2 +- src/Service/Traits/SelectDatabaseQuestion.php | 2 +- src/Service/Traits/SelectUserQuestion.php | 22 +++++++++++++++++++ 8 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/Service/Traits/SelectUserQuestion.php diff --git a/src/Console/BackupDatabaseCommand.php b/src/Console/BackupDatabaseCommand.php index d458d60..3471b22 100644 --- a/src/Console/BackupDatabaseCommand.php +++ b/src/Console/BackupDatabaseCommand.php @@ -26,7 +26,7 @@ class BackupDatabaseCommand extends Command protected function configure(): void { - $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database name'); $this->addArgument('file', InputArgument::OPTIONAL, 'Backup file name'); } diff --git a/src/Console/CreateDatabaseCommand.php b/src/Console/CreateDatabaseCommand.php index 0f5b397..ab2be03 100644 --- a/src/Console/CreateDatabaseCommand.php +++ b/src/Console/CreateDatabaseCommand.php @@ -22,14 +22,14 @@ class CreateDatabaseCommand extends Command protected function configure(): void { - $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database name'); } protected function execute(InputInterface $input, OutputInterface $output): int { $question = $this->getHelper('question'); - if (!$name = $input->getArgument('name')) { + if (!$name = $input->getArgument('database')) { $name = $question->ask($input, $output, new Question('Database name: ')); } diff --git a/src/Console/CreatePermissionCommand.php b/src/Console/CreatePermissionCommand.php index 6998f08..a5cb2d1 100644 --- a/src/Console/CreatePermissionCommand.php +++ b/src/Console/CreatePermissionCommand.php @@ -3,14 +3,18 @@ namespace App\Console; use App\Service\DatabaseService; +use App\Service\Traits\SelectDatabaseQuestion; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand('app:permissions:list')] class CreatePermissionCommand extends Command { + use SelectDatabaseQuestion; + public function __construct( private readonly DatabaseService $db, ) @@ -18,6 +22,13 @@ class CreatePermissionCommand extends Command parent::__construct(); } + public function configure(): void + { + $this->addArgument('name', InputArgument::OPTIONAL, 'User name'); + $this->addArgument('host', InputArgument::OPTIONAL, 'User host'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database'); + } + protected function execute(InputInterface $input, OutputInterface $output): int { $dbs = $this->db->listDatabases(); diff --git a/src/Console/DeleteDatabaseCommand.php b/src/Console/DeleteDatabaseCommand.php index 0aed5b8..2028619 100644 --- a/src/Console/DeleteDatabaseCommand.php +++ b/src/Console/DeleteDatabaseCommand.php @@ -24,7 +24,7 @@ class DeleteDatabaseCommand extends Command protected function configure(): void { - $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database name'); } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Console/PurgeDatabaseCommand.php b/src/Console/PurgeDatabaseCommand.php index c4ea6fe..45b17e6 100644 --- a/src/Console/PurgeDatabaseCommand.php +++ b/src/Console/PurgeDatabaseCommand.php @@ -24,7 +24,7 @@ class PurgeDatabaseCommand extends Command protected function configure(): void { - $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database name'); } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Console/RestoreDatabaseCommand.php b/src/Console/RestoreDatabaseCommand.php index 9caed3c..a9ceac3 100644 --- a/src/Console/RestoreDatabaseCommand.php +++ b/src/Console/RestoreDatabaseCommand.php @@ -28,7 +28,7 @@ class RestoreDatabaseCommand extends Command protected function configure(): void { - $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('database', InputArgument::OPTIONAL, 'Database name'); $this->addArgument('file', InputArgument::OPTIONAL, 'Backup file name'); } diff --git a/src/Service/Traits/SelectDatabaseQuestion.php b/src/Service/Traits/SelectDatabaseQuestion.php index 92ab9f3..ea11421 100644 --- a/src/Service/Traits/SelectDatabaseQuestion.php +++ b/src/Service/Traits/SelectDatabaseQuestion.php @@ -12,7 +12,7 @@ trait SelectDatabaseQuestion { $question = $this->getHelper('question'); - if (!$name = $input->getArgument('name')) { + if (!$name = $input->getArgument('database')) { $selectQuestion = new ChoiceQuestion('Database name: ', $this->db->listDatabases()); $name = $question->ask($input, $output, $selectQuestion); } diff --git a/src/Service/Traits/SelectUserQuestion.php b/src/Service/Traits/SelectUserQuestion.php new file mode 100644 index 0000000..f6e45db --- /dev/null +++ b/src/Service/Traits/SelectUserQuestion.php @@ -0,0 +1,22 @@ +getHelper('question'); + + if (!$name = $input->getArgument('name')) { + $selectQuestion = new ChoiceQuestion('Database name: ', $this->db->listDatabases()); + $name = $question->ask($input, $output, $selectQuestion); + } + + return $name; + } +} \ No newline at end of file