2025-04-08 23:00:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Loom\Spinner\Command;
|
|
|
|
|
2025-04-13 10:43:30 +01:00
|
|
|
use Loom\Spinner\Classes\Config\Config;
|
2025-04-12 15:14:28 +01:00
|
|
|
use Loom\Spinner\Classes\OS\System;
|
|
|
|
use Loom\Spinner\Command\Interface\ConsoleCommandInterface;
|
2025-04-08 23:00:21 +01:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2025-04-23 23:30:51 +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;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
class AbstractSpinnerCommand extends Command implements ConsoleCommandInterface
|
2025-04-08 23:00:21 +01:00
|
|
|
{
|
2025-04-13 10:43:30 +01:00
|
|
|
protected Config $config;
|
|
|
|
protected SymfonyStyle $style;
|
|
|
|
protected System $system;
|
2025-04-12 10:47:55 +01:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->system = new System();
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2025-04-08 23:00:21 +01:00
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$this->setStyle($input, $output);
|
|
|
|
|
2025-04-12 17:28:57 +01:00
|
|
|
$this->style->title('Loom Spinner');
|
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
|
2025-04-23 23:57:11 +01:00
|
|
|
protected function buildDockerComposeCommand(string $command, bool $withEnv = false, bool $daemon = true): string
|
2025-04-12 17:28:57 +01:00
|
|
|
{
|
|
|
|
return sprintf(
|
2025-04-23 23:57:11 +01:00
|
|
|
'cd %s && docker compose%s %s%s',
|
2025-04-23 23:30:51 +01:00
|
|
|
$this->config->getDataDirectory(),
|
2025-04-23 23:57:11 +01:00
|
|
|
$withEnv ? ' --env-file=' . $this->config->getDataDirectory() . '/.env' : '',
|
2025-04-12 17:28:57 +01:00
|
|
|
$command,
|
|
|
|
$daemon ? ' -d' : ''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-04-12 15:14:28 +01:00
|
|
|
private function setStyle(InputInterface $input, OutputInterface $output): void
|
2025-04-08 23:00:21 +01:00
|
|
|
{
|
|
|
|
$this->style = new SymfonyStyle($input, $output);
|
|
|
|
}
|
|
|
|
}
|