Add --working-dir

This commit is contained in:
Oliver Davies 2024-02-19 12:30:02 +00:00
parent 7d1aaf3104
commit e81e0cef71
2 changed files with 12 additions and 0 deletions

View file

@ -2,6 +2,7 @@
## Unrelased
- Add `--working-dir` to run versa in a different directory.
- Add `-t` as a shortcut for `--type`.
## 0.1.0

11
versa
View file

@ -24,6 +24,14 @@ $application->addOption(
suggestedValues: ['drupal', 'sculpin'],
);
$application->addOption(
name: 'working-dir',
shortcut: 'd',
mode: InputArgument::OPTIONAL,
description: 'The project\'s working directory',
default: '.',
);
$application->setCode(function (InputInterface $input): int {
// TODO: only allow defined commands - build, install, test, run.
switch ($input->getArgument('command')) {
@ -31,6 +39,7 @@ $application->setCode(function (InputInterface $input): int {
// TODO: Composer in Docker Compose?
$process = new Process(command: ['composer', 'install']);
$process->setTty(true);
$process->setWorkingDirectory($input->getOption('working-dir'));
$process->run();
break;
@ -40,6 +49,7 @@ $application->setCode(function (InputInterface $input): int {
// 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($input->getOption('working-dir'));
$process->run();
break;
}
@ -50,6 +60,7 @@ $application->setCode(function (InputInterface $input): int {
// TODO: commands in Docker Compose?
$process = new Process(command: ['./vendor/bin/phpunit']);
$process->setTty(true);
$process->setWorkingDirectory($input->getOption('working-dir'));
$process->run();
break;
}