mirror of
https://github.com/opdavies/versa.git
synced 2025-02-02 07:57:32 +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,
|
workingDir: $workingDir,
|
||||||
))->getLanguage();
|
))->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
|
// Attempt to prepopulate some of the options, such as the project type
|
||||||
// based on its dependencies.
|
// based on its dependencies.
|
||||||
// TODO: move this logic to a service so it can be tested.
|
// 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.
|
// with the option value if there is one.
|
||||||
$projectType = $input->getOption('type') ?? $projectType;
|
$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');
|
$isDockerCompose = $this->filesystem->exists($workingDir . '/docker-compose.yaml');
|
||||||
|
|
||||||
switch ($language) {
|
switch ($language) {
|
||||||
|
|
|
@ -32,6 +32,11 @@ final class InstallCommand extends AbstractCommand
|
||||||
))->getLanguage();
|
))->getLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(
|
||||||
|
assertion: ProjectLanguage::isValid($language),
|
||||||
|
description: sprintf('%s is not a supported language.', $language),
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Composer in Docker Compose?
|
// TODO: Composer in Docker Compose?
|
||||||
$process = Process::create(
|
$process = Process::create(
|
||||||
args: explode(separator: ' ', string: strval($args)),
|
args: explode(separator: ' ', string: strval($args)),
|
||||||
|
|
|
@ -39,6 +39,11 @@ final class PackageInstallCommand extends AbstractCommand
|
||||||
workingDir: $workingDir,
|
workingDir: $workingDir,
|
||||||
))->getLanguage();
|
))->getLanguage();
|
||||||
|
|
||||||
|
assert(
|
||||||
|
assertion: ProjectLanguage::isValid($language),
|
||||||
|
description: sprintf('%s is not a supported language.', $language),
|
||||||
|
);
|
||||||
|
|
||||||
switch ($language) {
|
switch ($language) {
|
||||||
case ProjectLanguage::PHP->value:
|
case ProjectLanguage::PHP->value:
|
||||||
$process = Process::create(
|
$process = Process::create(
|
||||||
|
|
|
@ -32,6 +32,11 @@ final class RunCommand extends AbstractCommand
|
||||||
workingDir: $workingDir,
|
workingDir: $workingDir,
|
||||||
))->getLanguage();
|
))->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
|
// Attempt to prepopulate some of the options, such as the project type
|
||||||
// based on its dependencies.
|
// based on its dependencies.
|
||||||
// TODO: move this logic to a service so it can be tested.
|
// 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.
|
// with the option value if there is one.
|
||||||
$projectType = $input->getOption('type') ?? $projectType;
|
$projectType = $input->getOption('type') ?? $projectType;
|
||||||
|
|
||||||
|
assert(
|
||||||
|
assertion: ProjectType::isValid($projectType),
|
||||||
|
description: sprintf('%s is not a supported project type.', $projectType),
|
||||||
|
);
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
$isDockerCompose = $filesystem->exists($workingDir . '/docker-compose.yaml');
|
$isDockerCompose = $filesystem->exists($workingDir . '/docker-compose.yaml');
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,16 @@ enum ProjectLanguage: string
|
||||||
{
|
{
|
||||||
case JavaScript = 'javascript';
|
case JavaScript = 'javascript';
|
||||||
case PHP = 'php';
|
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 Drupal = 'drupal';
|
||||||
case Sculpin = 'sculpin';
|
case Sculpin = 'sculpin';
|
||||||
case Symfony = 'symfony';
|
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