2025-04-08 23:00:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Loom\Spinner\Command;
|
|
|
|
|
2025-04-12 10:47:55 +01:00
|
|
|
use Loom\Utility\FilePath\FilePath;
|
2025-04-08 23:00:21 +01:00
|
|
|
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;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
#[AsCommand(name: 'spin', description: 'Spin up a new development environment')]
|
|
|
|
class SpinCommand extends AbstractSpinnerCommand
|
|
|
|
{
|
2025-04-12 10:47:55 +01:00
|
|
|
protected function configure(): void
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'The name for your Docker container.')
|
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'The absolute path to your projects root directory.');
|
|
|
|
}
|
|
|
|
|
2025-04-08 23:00:21 +01:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$this->setStyle($input, $output);
|
|
|
|
|
2025-04-12 10:47:55 +01:00
|
|
|
$projectDirectory = new FilePath($input->getArgument('path'));
|
|
|
|
|
|
|
|
if (!$projectDirectory->exists() || !$projectDirectory->isDirectory()) {
|
|
|
|
$this->style->error('The provided path is not a valid directory.');
|
|
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->system->isDockerEngineRunning()) {
|
|
|
|
$this->style->error('It looks like the Docker Engine is not running. Please start it and try again.');
|
|
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
|
|
|
|
2025-04-08 23:00:21 +01:00
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|