Skip to content

Commit

Permalink
t2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 18, 2025
1 parent e589205 commit 22e940b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions .vortex/installer/src/Prompts/PromptManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DrevOps\Installer\Prompts\Handlers\HandlerInterface;
use DrevOps\Installer\Utils\Config;
use DrevOps\Installer\Utils\Converter;
use DrevOps\Installer\Utils\Env;
use DrevOps\Installer\Utils\Validator;
use Laravel\Prompts\Prompt;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function prompt() {
hint: 'We will use this name in the project and in the documentation.',
placeholder: 'E.g. My Site',
required: TRUE,
default: $this->default($n, Str2Name::label(Utils::getEnvOrDefault('VORTEX_PROJECT', basename((string) $this->config->getDst())))),
default: $this->default($n, Str2Name::label(Env::get('VORTEX_PROJECT', basename((string) $this->config->getDst())))),
transform: fn(string $v) => trim($v),
validate: fn($v) => Str2Name::label($v) !== $v ? 'Please enter a valid name' : NULL,
), PromptFields::NAME)
Expand Down Expand Up @@ -120,9 +121,9 @@ public function prompt() {
fn($r) => $r['code_provider'] === 'github',
fn($r, $pr, $n) => text(
label: '🔑 GitHub access token (optional)',
hint: Utils::getEnvOrDefault('GITHUB_TOKEN') ? 'Read from GITHUB_TOKEN environment variable.' : 'Create a new token with "repo" scopes at https://github.com/settings/tokens/new',
hint: Env::get('GITHUB_TOKEN') ? 'Read from GITHUB_TOKEN environment variable.' : 'Create a new token with "repo" scopes at https://github.com/settings/tokens/new',
placeholder: 'E.g. ghp_1234567890',
default: $this->default($n, Utils::getEnvOrDefault('GITHUB_TOKEN')),
default: $this->default($n, Env::get('GITHUB_TOKEN')),
transform: fn(string $v) => trim($v),
validate: fn($v) => !empty($v) && !str_starts_with($v, 'ghp_') ? 'Please enter a valid token starting with "ghp_"' : NULL,
), PromptFields::GITHUB_TOKEN)
Expand Down Expand Up @@ -172,6 +173,7 @@ public function prompt() {
required: TRUE,
default: $this->default($n, Converter::abbreviation($r['machine_name'], 4, ['_'])),
transform: fn(string $v) => trim($v),
// @todo Fix validation here.
validate: fn($v) => Converter::abbreviation($v) !== $v ? 'Please enter a valid module prefix: only lowercase letters, numbers, and underscores are allowed.' : NULL,
), PromptFields::MODULE_PREFIX)

Expand Down Expand Up @@ -260,7 +262,7 @@ public function prompt() {
label: 'Provision type',
hint: 'Selecting "Profile" will install site from a profile rather than a database dump.',
options: [
'database' => 'Database dump',
'database' => 'Import from database dump',
'profile' => 'Install from profile',
],
default: $this->default($n, 'database'),
Expand Down
6 changes: 3 additions & 3 deletions .vortex/installer/src/Utils/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ public static function parseUri(string $src) {
throw new RuntimeException(sprintf('Invalid remote repository format: "%s".', $src));
}
$repo = $matches[1];
$ref = $matches[2] ?? 'HEAD';
$ref = $matches[2] ?? 'stable';
}
elseif (str_starts_with($src, 'file://')) {
if (!preg_match('#^file://(.+?)(?:@(.+))?$#', $src, $matches)) {
throw new RuntimeException(sprintf('Invalid remote repository format: "%s".', $src));
}
$repo = $matches[1];
$ref = $matches[2] ?? 'HEAD';
$ref = $matches[2] ?? 'stable';
}
else {
if (!preg_match('#^(.+?)(?:@(.+))?$#', $src, $matches)) {
throw new RuntimeException(sprintf('Invalid local repository format: "%s".', $src));
}
$repo = rtrim($matches[1], '/');
$ref = $matches[2] ?? 'HEAD';
$ref = $matches[2] ?? 'stable';

return [$repo, $ref];
}
Expand Down
2 changes: 1 addition & 1 deletion .vortex/installer/src/Utils/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function getFromDstDotenv(string $name, mixed $default = NULL): mi

$parsed = static::parseDotenv($file);

return $parsed !== [] ? $parsed[$name] ?? $default : $default;
return $parsed !== [] ? ($parsed[$name] ?? $default) : $default;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions .vortex/installer/src/Utils/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function summary(Config $config, array $responses): void {
// @todo Review below - it should show the version of Vortex that will be
// installed and a commit to be installed from.
$values['Vortex version'] = $config->get(Config::VORTEX_VERSION);
$values['Vortex commit'] = $config->get(Config::COMMIT, 'Latest');
[$repo, $ref] = Downloader::parseUri($config->get(Config::REPO_URI));
$values['Vortex commit'] = $ref;

$values[] = self::EMPTY_LINE;

Expand Down Expand Up @@ -195,7 +196,7 @@ protected static function printList(array $values): void {
table([], $rows);
}

protected static function formatYesNo(string $value): string {
protected static function formatYesNo(string|bool|int $value): string {
return $value === '1' || $value === 1 || $value === TRUE ? 'Yes' : 'No';
}

Expand Down

0 comments on commit 22e940b

Please sign in to comment.