Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion legacy/src/Command/Organization/OrganizationCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ protected function chooseMember(Organization $organization): Member
}
$userId = $this->questionHelper->choose($choices, 'Enter a number to choose a user:', $default);
} else {
$userId = $this->questionHelper->askInput('Enter an email address to choose a user', null, array_values($emailAddresses), function (string $email) use ($emailAddresses): string {
$userId = $this->questionHelper->askInput('Enter an email address to choose a user', null, array_values($emailAddresses), function (?string $email) use ($emailAddresses): string {
if ($email === null) {
throw new InvalidArgumentException('An email address is required');
}
if (($key = array_search($email, $emailAddresses)) === false) {
throw new InvalidArgumentException('User not found: ' . $email);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
} else {
$questionText = 'Optionally, enter a list of permissions to add (separated by commas)';
}
$response = $this->questionHelper->askInput($questionText, null, [], function ($value) {
$response = $this->questionHelper->askInput($questionText, null, [], function (?string $value): ?string {
if ($value === null) {
return null;
}
foreach (ArrayArgument::split([$value]) as $permission) {
if (!\in_array($permission, self::$allPermissions)) {
throw new InvalidArgumentException('Unrecognized permission: ' . $permission);
}
}
return $value;
});
$permissions = ArrayArgument::split([$response]);
$permissions = $response === null ? [] : ArrayArgument::split([$response]);
$this->stdErr->writeln('');
}

Expand Down
7 changes: 5 additions & 2 deletions legacy/src/Command/Team/User/TeamUserAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$emails[] = $info->email;
}
}
$identifier = $this->questionHelper->askInput('Enter an email address to add a user', null, $emails, function (string $value): string {
$identifier = $this->questionHelper->askInput('Enter an email address to add a user', null, $emails, function (?string $value): string {
if ($value === null) {
throw new InvalidArgumentException('An email address is required');
}
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Invalid email address:' . $value);
throw new InvalidArgumentException('Invalid email address: ' . $value);
}
return $value;
});
Expand Down
9 changes: 6 additions & 3 deletions legacy/src/Selector/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ private function offerProjectChoice(array $projectInfos, SelectorConfig $config)
}
}
asort($autocomplete, SORT_NATURAL | SORT_FLAG_CASE);
return $this->questionHelper->askInput($config->enterProjectText, null, array_values($autocomplete), function ($value) use ($autocomplete): string {
[$id, ] = explode(' - ', $value);
return $this->questionHelper->askInput($config->enterProjectText, null, array_values($autocomplete), function (?string $value) use ($autocomplete): string {
[$id] = explode(' - ', $value ?? '', 2);
if (empty(trim($id))) {
throw new InvalidArgumentException('A project ID is required');
}
Expand Down Expand Up @@ -495,7 +495,10 @@ private function offerEnvironmentChoice(InputInterface $input, Project $project,
$ids = array_keys($environments);
sort($ids, SORT_NATURAL | SORT_FLAG_CASE);

$id = $this->questionHelper->askInput($config->enterEnvText, $defaultEnvironmentId, array_keys($environments), function (string $value) use ($environments): string {
$id = $this->questionHelper->askInput($config->enterEnvText, $defaultEnvironmentId, array_keys($environments), function (?string $value) use ($environments): string {
if ($value === null || $value === '') {
throw new \RuntimeException('An environment ID is required');
}
if (!isset($environments[$value])) {
throw new \RuntimeException('Environment not found: ' . $value);
}
Expand Down
Loading