Add Start and Stop commands
This commit is contained in:
parent
ba26a6bc17
commit
977822936b
3 changed files with 105 additions and 1 deletions
|
@ -3,14 +3,18 @@
|
|||
|
||||
use Loom\Spinner\Command\DestroyCommand;
|
||||
use Loom\Spinner\Command\SpinCommand;
|
||||
use Loom\Spinner\Command\StartCommand;
|
||||
use Loom\Spinner\Command\StopCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$application = new Application('Loom Spinner');
|
||||
|
||||
$application->add(new SpinCommand());
|
||||
$application->add(new DestroyCommand());
|
||||
$application->add(new SpinCommand());
|
||||
$application->add(new StartCommand());
|
||||
$application->add(new StopCommand());
|
||||
|
||||
try {
|
||||
$application->run();
|
||||
|
|
50
src/Command/StartCommand.php
Normal file
50
src/Command/StartCommand.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Loom\Spinner\Command;
|
||||
|
||||
use Loom\Spinner\Classes\Config\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'spin:start', description: 'Start a development environment')]
|
||||
class StartCommand extends AbstractSpinnerCommand
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addArgument(
|
||||
'name',
|
||||
InputArgument::REQUIRED,
|
||||
'The name of the project (as used when running spin:up).'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (parent::execute($input, $output)) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->config = new Config($input->getArgument('name'));
|
||||
|
||||
if (!file_exists($this->config->getDataDirectory())) {
|
||||
$this->style->error('No project found with the provided name.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
passthru($this->buildDockerComposeCommand('start', false, false));
|
||||
} catch (\Exception $exception) {
|
||||
$this->style->error('An error occurred while starting the project: ' . $exception->getMessage());
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
50
src/Command/StopCommand.php
Normal file
50
src/Command/StopCommand.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Loom\Spinner\Command;
|
||||
|
||||
use Loom\Spinner\Classes\Config\Config;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'spin:stop', description: 'Stop a currently running development environment')]
|
||||
class StopCommand extends AbstractSpinnerCommand
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addArgument(
|
||||
'name',
|
||||
InputArgument::REQUIRED,
|
||||
'The name of the project (as used when running spin:up).'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if (parent::execute($input, $output)) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$this->config = new Config($input->getArgument('name'));
|
||||
|
||||
if (!file_exists($this->config->getDataDirectory())) {
|
||||
$this->style->error('No project found with the provided name.');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
passthru($this->buildDockerComposeCommand('stop', false, false));
|
||||
} catch (\Exception $exception) {
|
||||
$this->style->error('An error occurred while starting the project: ' . $exception->getMessage());
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue