Add symfony console table and app: for commands
This commit is contained in:
parent
6aae797f16
commit
62e8f87ec8
@ -11,7 +11,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
#[AsCommand('db:backup')]
|
#[AsCommand('app:db:backup')]
|
||||||
class BackupDatabaseCommand extends Command
|
class BackupDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
use SelectDatabaseQuestion;
|
use SelectDatabaseQuestion;
|
||||||
|
@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
#[AsCommand('db:create')]
|
#[AsCommand('app:db:create')]
|
||||||
class CreateDatabaseCommand extends Command
|
class CreateDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
#[AsCommand('user:create')]
|
#[AsCommand('app:user:create')]
|
||||||
class CreateUserCommand extends Command
|
class CreateUserCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
#[AsCommand('db:delete')]
|
#[AsCommand('app:db:delete')]
|
||||||
class DeleteDatabaseCommand extends Command
|
class DeleteDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
use SelectDatabaseQuestion;
|
use SelectDatabaseQuestion;
|
||||||
|
@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||||
use Symfony\Component\Console\Question\Question;
|
use Symfony\Component\Console\Question\Question;
|
||||||
|
|
||||||
#[AsCommand('user:delete')]
|
#[AsCommand('app:user:delete')]
|
||||||
class DeleteUserCommand extends Command
|
class DeleteUserCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -7,8 +7,9 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
#[AsCommand('db:list')]
|
#[AsCommand('app:db:list')]
|
||||||
class ListDatabasesCommand extends Command
|
class ListDatabasesCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -21,11 +22,17 @@ class ListDatabasesCommand extends Command
|
|||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$dbs = $this->db->listDatabases();
|
$dbs = $this->db->listDatabases();
|
||||||
|
$style = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$output->writeln('List of databases:');
|
$table = $style
|
||||||
|
->createTable()
|
||||||
|
->setHeaders(['Name'])
|
||||||
|
->setHeaderTitle('List of databases')
|
||||||
|
;
|
||||||
foreach ($dbs as $db) {
|
foreach ($dbs as $db) {
|
||||||
$output->writeln(sprintf(' -%s', $db));
|
$table->addRow([$db]);
|
||||||
}
|
}
|
||||||
|
$table->render();
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,9 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
#[AsCommand('user:list')]
|
#[AsCommand('app:user:list')]
|
||||||
class ListUsersCommand extends Command
|
class ListUsersCommand extends Command
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -20,17 +21,19 @@ class ListUsersCommand extends Command
|
|||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
|
$style = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
$users = $this->db->listUsers();
|
$users = $this->db->listUsers();
|
||||||
|
|
||||||
$output->writeln('List of users:');
|
$table = $style
|
||||||
|
->createTable()
|
||||||
|
->setHeaders(['Name', 'Host', 'Plugin'])
|
||||||
|
->setHeaderTitle('List of users')
|
||||||
|
;
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$line = sprintf(' -%s @%s', $user['name'], $user['host']);
|
$table->addRow([$user['name'], $user['host'], $user['plugin'] ?? '']);
|
||||||
if (!empty($plugin = $user['plugin'])) {
|
|
||||||
$line .= sprintf(' (%s)', $plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
$output->writeln($line);
|
|
||||||
}
|
}
|
||||||
|
$table->render();
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
#[AsCommand('db:purge')]
|
#[AsCommand('app:db:purge')]
|
||||||
class PurgeDatabaseCommand extends Command
|
class PurgeDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
use SelectDatabaseQuestion;
|
use SelectDatabaseQuestion;
|
||||||
|
@ -13,7 +13,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
#[AsCommand('db:restore')]
|
#[AsCommand('app:db:restore')]
|
||||||
class RestoreDatabaseCommand extends Command
|
class RestoreDatabaseCommand extends Command
|
||||||
{
|
{
|
||||||
use SelectDatabaseQuestion;
|
use SelectDatabaseQuestion;
|
||||||
|
Loading…
Reference in New Issue
Block a user