Run docker compose up

This commit is contained in:
Oliver Davies 2024-02-19 12:35:17 +00:00
parent e81e0cef71
commit 959a0584e4
2 changed files with 20 additions and 8 deletions

View file

@ -2,6 +2,7 @@
## Unrelased ## Unrelased
- Run `docker compose up` if there is a `docker-compose.yaml` file when running `versa run`.
- Add `--working-dir` to run versa in a different directory. - Add `--working-dir` to run versa in a different directory.
- Add `-t` as a shortcut for `--type`. - Add `-t` as a shortcut for `--type`.

27
versa
View file

@ -6,6 +6,7 @@ require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\SingleCommandApplication; use Symfony\Component\Console\SingleCommandApplication;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
$application = new SingleCommandApplication(); $application = new SingleCommandApplication();
@ -44,14 +45,24 @@ $application->setCode(function (InputInterface $input): int {
break; break;
case 'run': case 'run':
switch ($input->getOption('type')) { $workingDir = $input->getOption('working-dir');
case 'sculpin': $filesystem = new Filesystem();
// TODO: how to pass arbitrary arguments, such as `--port 8001`?
$process = new Process(command: ['./vendor/bin/sculpin', 'generate', '--server', '--watch']); if ($filesystem->exists($workingDir.'/docker-compose.yaml')) {
$process->setTty(true); $process = new Process(command: ['docker', 'compose', 'up']);
$process->setWorkingDirectory($input->getOption('working-dir')); $process->setTty(true);
$process->run(); $process->setWorkingDirectory($workingDir);
break; $process->run();
} else {
switch ($input->getOption('type')) {
case 'sculpin':
// TODO: how to pass arbitrary arguments, such as `--port 8001`?
$process = new Process(command: ['./vendor/bin/sculpin', 'generate', '--server', '--watch']);
$process->setTty(true);
$process->setWorkingDirectory($workingDir);
$process->run();
break;
}
} }
break; break;