General command

This commit is contained in:
Juan Pablo Vial
2024-12-22 11:03:03 -03:00
parent ab08f13d2f
commit dc3ef0a3bb
2 changed files with 42 additions and 0 deletions

View File

@ -1,6 +1,8 @@
<?php <?php
return [ return [
'commands' => [ 'commands' => [
ProVM\Command\Generate::class,
ProVM\Command\GenerateMigrations::class, ProVM\Command\GenerateMigrations::class,
ProVM\Command\GenerateSeeds::class,
] ]
]; ];

View File

@ -0,0 +1,40 @@
<?php
namespace ProVM\Command;
use Symfony\Component\Console;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[Console\Attribute\AsCommand(name: 'generate', description: 'Generate database migrations and seeds.')]
class Generate extends Console\Command\Command
{
protected function configure()
{
parent::configure();
$this->addOption('dry-run', 'd');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new Console\Style\SymfonyStyle($input, $output);
$io->title('Generate');
$dryRun = $input->hasOption('dry-run');
$commands = [
'generate:migrations',
'generate:seeds'
];
foreach ($commands as $commandName) {
$command = $this->getApplication()->find($commandName);
$arguments = [
'command' => $commandName,
];
if ($dryRun) {
$arguments['--dry-run'] = true;
}
$command->run(new Console\Input\ArrayInput($arguments), $output);
}
return Console\Command\Command::SUCCESS;
}
}