mirror of
https://github.com/opdavies/versa.git
synced 2025-01-22 19:47:33 +00:00
Assert the project language and type are valid
This commit is contained in:
parent
d541f064a5
commit
e499d42fa5
|
@ -32,6 +32,11 @@ final class BuildCommand extends AbstractCommand
|
|||
workingDir: $workingDir,
|
||||
))->getLanguage();
|
||||
|
||||
assert(
|
||||
assertion: ProjectLanguage::isValid($language),
|
||||
description: sprintf('%s is not a supported language.', $language),
|
||||
);
|
||||
|
||||
// Attempt to prepopulate some of the options, such as the project type
|
||||
// based on its dependencies.
|
||||
// TODO: move this logic to a service so it can be tested.
|
||||
|
@ -60,6 +65,11 @@ final class BuildCommand extends AbstractCommand
|
|||
// with the option value if there is one.
|
||||
$projectType = $input->getOption('type') ?? $projectType;
|
||||
|
||||
assert(
|
||||
assertion: ProjectType::isValid($projectType),
|
||||
description: sprintf('%s is not a supported project type.', $projectType),
|
||||
);
|
||||
|
||||
$isDockerCompose = $this->filesystem->exists($workingDir . '/docker-compose.yaml');
|
||||
|
||||
switch ($language) {
|
||||
|
|
|
@ -32,6 +32,11 @@ final class InstallCommand extends AbstractCommand
|
|||
))->getLanguage();
|
||||
}
|
||||
|
||||
assert(
|
||||
assertion: ProjectLanguage::isValid($language),
|
||||
description: sprintf('%s is not a supported language.', $language),
|
||||
);
|
||||
|
||||
// TODO: Composer in Docker Compose?
|
||||
$process = Process::create(
|
||||
args: explode(separator: ' ', string: strval($args)),
|
||||
|
|
|
@ -39,6 +39,11 @@ final class PackageInstallCommand extends AbstractCommand
|
|||
workingDir: $workingDir,
|
||||
))->getLanguage();
|
||||
|
||||
assert(
|
||||
assertion: ProjectLanguage::isValid($language),
|
||||
description: sprintf('%s is not a supported language.', $language),
|
||||
);
|
||||
|
||||
switch ($language) {
|
||||
case ProjectLanguage::PHP->value:
|
||||
$process = Process::create(
|
||||
|
|
|
@ -32,6 +32,11 @@ final class RunCommand extends AbstractCommand
|
|||
workingDir: $workingDir,
|
||||
))->getLanguage();
|
||||
|
||||
assert(
|
||||
assertion: ProjectLanguage::isValid($language),
|
||||
description: sprintf('%s is not a supported language.', $language),
|
||||
);
|
||||
|
||||
// Attempt to prepopulate some of the options, such as the project type
|
||||
// based on its dependencies.
|
||||
// TODO: move this logic to a service so it can be tested.
|
||||
|
@ -60,6 +65,11 @@ final class RunCommand extends AbstractCommand
|
|||
// with the option value if there is one.
|
||||
$projectType = $input->getOption('type') ?? $projectType;
|
||||
|
||||
assert(
|
||||
assertion: ProjectType::isValid($projectType),
|
||||
description: sprintf('%s is not a supported project type.', $projectType),
|
||||
);
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
$isDockerCompose = $filesystem->exists($workingDir . '/docker-compose.yaml');
|
||||
|
||||
|
|
|
@ -8,4 +8,16 @@ enum ProjectLanguage: string
|
|||
{
|
||||
case JavaScript = 'javascript';
|
||||
case PHP = 'php';
|
||||
|
||||
/**
|
||||
* @param non-empty-string $language
|
||||
*/
|
||||
public static function isValid(string $language): bool
|
||||
{
|
||||
return in_array(
|
||||
haystack: array_column(self::cases(), 'value'),
|
||||
needle: $language,
|
||||
strict: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,4 +13,16 @@ enum ProjectType: string
|
|||
case Drupal = 'drupal';
|
||||
case Sculpin = 'sculpin';
|
||||
case Symfony = 'symfony';
|
||||
|
||||
/**
|
||||
* @param non-empty-string $projectType
|
||||
*/
|
||||
public static function isValid(string $projectType): bool
|
||||
{
|
||||
return in_array(
|
||||
haystack: array_column(self::cases(), 'value'),
|
||||
needle: $projectType,
|
||||
strict: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue