Make database name question more specific

This commit is contained in:
Tim 2024-09-24 00:19:45 +02:00
parent 1aad1a59e4
commit 153f04ccd7
8 changed files with 40 additions and 7 deletions

View File

@ -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');
}

View File

@ -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: '));
}

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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');
}

View File

@ -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);
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Service\Traits;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
trait SelectUserQuestion
{
private function getUserName(InputInterface $input, OutputInterface $output): string
{
$question = $this->getHelper('question');
if (!$name = $input->getArgument('name')) {
$selectQuestion = new ChoiceQuestion('Database name: ', $this->db->listDatabases());
$name = $question->ask($input, $output, $selectQuestion);
}
return $name;
}
}