From 977822936bbdf86750529d10dd4afce4e53ab82f Mon Sep 17 00:00:00 2001 From: Danny Date: Thu, 24 Apr 2025 00:41:13 +0100 Subject: [PATCH] Add Start and Stop commands --- bin/spinner | 6 ++++- src/Command/StartCommand.php | 50 ++++++++++++++++++++++++++++++++++++ src/Command/StopCommand.php | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/Command/StartCommand.php create mode 100644 src/Command/StopCommand.php diff --git a/bin/spinner b/bin/spinner index 7a5a3a9..b3cae0d 100755 --- a/bin/spinner +++ b/bin/spinner @@ -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(); diff --git a/src/Command/StartCommand.php b/src/Command/StartCommand.php new file mode 100644 index 0000000..af0768d --- /dev/null +++ b/src/Command/StartCommand.php @@ -0,0 +1,50 @@ +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; + } +} \ No newline at end of file diff --git a/src/Command/StopCommand.php b/src/Command/StopCommand.php new file mode 100644 index 0000000..03a5ae4 --- /dev/null +++ b/src/Command/StopCommand.php @@ -0,0 +1,50 @@ +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; + } +} \ No newline at end of file