setName('app:install')
->setDescription('Install the framework: import schema, write config, lock.')
->addOption('db-host', null, InputOption::VALUE_REQUIRED, 'DB host', 'localhost')
->addOption('db-name', null, InputOption::VALUE_REQUIRED, 'DB name')
->addOption('db-user', null, InputOption::VALUE_REQUIRED, 'DB user')
->addOption('db-pass', null, InputOption::VALUE_REQUIRED, 'DB password')
->addOption('url', null, InputOption::VALUE_REQUIRED, 'Site URL', 'https://example.com')
->addOption('name', null, InputOption::VALUE_REQUIRED, 'Project name', 'SeedProject')
->addOption('force', null, InputOption::VALUE_NONE, 'Re-run even if already installed');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$installer = new Installer();
if ($installer->isInstalled() && !$input->getOption('force')) {
$output->writeln('Already installed. Use --force to re-run.');
return Command::FAILURE;
}
foreach (['db-name', 'db-user', 'db-pass'] as $req) {
if (!$input->getOption($req)) {
$output->writeln("--{$req} is required.");
return Command::FAILURE;
}
}
try {
$installer->run([
'url' => $input->getOption('url'),
'name' => $input->getOption('name'),
'db' => [
'host' => $input->getOption('db-host'),
'name' => $input->getOption('db-name'),
'user' => $input->getOption('db-user'),
'pass' => $input->getOption('db-pass'),
],
]);
} catch (\Throwable $e) {
$output->writeln('Install failed: ' . $e->getMessage() . '');
return Command::FAILURE;
}
$output->writeln('Install complete. config.php written, schema imported, lock set.');
return Command::SUCCESS;
}
}