2025-04-08 23:00:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Loom\Spinner\Command;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
2025-04-12 10:47:55 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2025-04-08 23:00:21 +01:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2025-04-12 17:28:57 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2025-04-08 23:00:21 +01:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
2025-04-12 17:28:57 +01:00
|
|
|
#[AsCommand(name: 'spin:up', description: 'Spin up a new development environment')]
|
2025-04-08 23:00:21 +01:00
|
|
|
class SpinCommand extends AbstractSpinnerCommand
|
|
|
|
{
|
2025-04-12 17:28:57 +01:00
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2025-04-12 10:47:55 +01:00
|
|
|
protected function configure(): void
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'The name for your Docker container.')
|
2025-04-12 17:28:57 +01:00
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'The absolute path to your projects root directory.')
|
|
|
|
->addOption('php', null, InputOption::VALUE_REQUIRED, 'The PHP version to use (e.g., 8.0).', $this->getDefaultPhpVersion());
|
2025-04-12 10:47:55 +01:00
|
|
|
}
|
|
|
|
|
2025-04-08 23:00:21 +01:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
2025-04-12 17:28:57 +01:00
|
|
|
if (parent::execute($input, $output)) {
|
2025-04-12 10:47:55 +01:00
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
|
2025-04-12 17:28:57 +01:00
|
|
|
if ($this->filePaths->get('projectData')->exists()) {
|
|
|
|
$this->style->warning('Project data already exists. Skipping new build.');
|
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->style->success("Spinning up a new development environment...");
|
|
|
|
|
|
|
|
mkdir($this->filePaths->get('projectData')->getProvidedPath(), 0777, true);
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
$this->filePaths->get('projectEnv')->getProvidedPath(),
|
|
|
|
sprintf(
|
|
|
|
file_get_contents($this->filePaths->get('envTemplate')->getAbsolutePath()),
|
|
|
|
$this->filePaths->get('project')->getAbsolutePath(),
|
|
|
|
$input->getArgument('name'),
|
|
|
|
$input->getOption('php')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2025-04-08 23:00:21 +01:00
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|