Skip to content

Commit

Permalink
Limit attempts on input for automation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredfholgate committed Jul 9, 2024
1 parent d10e0dc commit c7e1647
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ALZ/Private/Config-Helpers/Request-ConfigurationValue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function Request-ConfigurationValue {
Write-InformationColored "[allowed: $allowedValues] " -ForegroundColor Yellow -InformationAction Continue
}

$attempt = 0
$maxAttempts = 10

do {
Write-InformationColored "$($configName) " -ForegroundColor Yellow -NoNewline -InformationAction Continue
if ($hasDefaultValue) {
Expand Down Expand Up @@ -82,8 +85,15 @@ function Request-ConfigurationValue {
}

$shouldRetry = $validationError -and $withRetries

$attempt += 1
}
while (($hasNotSpecifiedValue -or $isDisallowedValue -or $isNotValid) -and $shouldRetry -and $attempt -lt $maxAttempts)

if($attempt -eq $maxAttempts) {
Write-InformationColored "Max attempts reached for getting input value. Exiting..." -ForegroundColor Red -InformationAction Continue
throw "Max attempts reached for getting input value. Exiting..."
}
while (($hasNotSpecifiedValue -or $isDisallowedValue -or $isNotValid) -and $shouldRetry)

Write-InformationColored "" -InformationAction Continue
}

0 comments on commit c7e1647

Please sign in to comment.