Add range and mixed selection support for config diagnostics (#10338)

This commit is contained in:
Alex
2026-02-21 23:22:46 +05:00
committed by GitHub
parent 3c1b64ab06
commit f2cbf47073

View File

@@ -420,20 +420,65 @@ function Read-ConfigSelection {
Write-Host " [$idx] $($allFiles[$i].Name)" -ForegroundColor Gray Write-Host " [$idx] $($allFiles[$i].Name)" -ForegroundColor Gray
} }
$selectionInput = Read-Host "Enter numbers separated by comma (e.g. 1,3,5) or '0' to run all" $selectionInput = Read-Host "Enter numbers (e.g. 1,3,5) , ranges (e.g. 2-7), or mixed (e.g. 1,5-10,12). '0' for all"
$trimmed = $selectionInput.Trim() $trimmed = $selectionInput.Trim()
if ($trimmed -eq '0') { if ($trimmed -eq '0') {
return $allFiles return $allFiles
} }
$numbers = $selectionInput -split "[\,\s]+" | Where-Object { $_ -match '^\d+$' } | ForEach-Object { [int]$_ } $parts = $selectionInput -split '[,\s]+' | Where-Object { $_ -match '^\d+(-\d+)?$' }
$valid = $numbers | Where-Object { $_ -ge 1 -and $_ -le $allFiles.Count } | Select-Object -Unique if ($parts.Count -eq 0) {
if (-not $valid -or $valid.Count -eq 0) {
Write-Host "" Write-Host ""
Write-Host "No configs selected. Try again." -ForegroundColor Yellow Write-Host "Invalid input format. Use numbers, ranges (1-5), or combinations (1,3-7,10). Try again." -ForegroundColor Yellow
continue continue
} }
$selectedIndices = @()
$hasErrors = $false
foreach ($part in $parts) {
if ($part -match '^(\d+)-(\d+)$') {
$start = [int]$matches[1]
$end = [int]$matches[2]
if ($start -gt $end) {
Write-Host " [WARN] Invalid range '$part' (start > end). Skipping." -ForegroundColor Yellow
$hasErrors = $true
continue
}
if ($start -lt 1 -or $end -gt $allFiles.Count) {
Write-Host " [WARN] Range '$part' out of bounds (valid: 1-$($allFiles.Count)). Skipping invalid parts." -ForegroundColor Yellow
$hasErrors = $true
$start = [Math]::Max($start, 1)
$end = [Math]::Min($end, $allFiles.Count)
}
for ($i = $start; $i -le $end; $i++) {
$selectedIndices += $i
}
} else {
$num = [int]$part
if ($num -ge 1 -and $num -le $allFiles.Count) {
$selectedIndices += $num
} else {
Write-Host " [WARN] Number '$num' out of bounds (valid: 1-$($allFiles.Count)). Skipping." -ForegroundColor Yellow
$hasErrors = $true
}
}
}
$valid = $selectedIndices | Sort-Object -Unique | Where-Object { $_ -ge 1 -and $_ -le $allFiles.Count }
if ($valid.Count -eq 0) {
Write-Host ""
Write-Host "No valid configs selected. Try again." -ForegroundColor Yellow
continue
}
# Checker
Write-Host "Selected configs: $($valid -join ', ')" -ForegroundColor Green
if ($hasErrors) {
Write-Host "Some entries were skipped due to errors (see warnings above)." -ForegroundColor Yellow
}
return $valid | ForEach-Object { $allFiles[$_ - 1] } return $valid | ForEach-Object { $allFiles[$_ - 1] }
} }