Use an Enum for project type conditions

This commit is contained in:
Oliver Davies 2024-02-20 00:57:04 +00:00
parent 0eb7d1a1b6
commit 44e7f63760
3 changed files with 16 additions and 2 deletions

View file

@ -4,6 +4,7 @@
"versa"
],
"directories": [
"src",
"vendor"
],
"check-requirements": true,

12
src/Enum/ProjectType.php Normal file
View file

@ -0,0 +1,12 @@
<?php
declare(strict_type=1);
namespace App\Enum;
enum ProjectType: string
{
// PHP.
case Drupal = 'drupal';
case Sculpin = 'sculpin';
}

5
versa
View file

@ -3,6 +3,7 @@
<?php
require __DIR__.'/vendor/autoload.php';
use App\Enum\ProjectType;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\SingleCommandApplication;
@ -52,7 +53,7 @@ $application->setCode(function (InputInterface $input): int {
switch ($input->getArgument('command')) {
case 'build':
switch ($input->getOption('type')) {
case 'sculpin':
case ProjectType::Sculpin->value:
$process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', $extraArgs]));
$process->setTty(true);
$process->setWorkingDirectory($workingDir);
@ -78,7 +79,7 @@ $application->setCode(function (InputInterface $input): int {
$process->run();
} else {
switch ($input->getOption('type')) {
case 'sculpin':
case ProjectType::Sculpin->value:
$process = new Process(command: array_filter(['./vendor/bin/sculpin', 'generate', '--server', '--watch', $extraArgs]));
$process->setTimeout(null);
$process->setTty(true);