Skip to content

Commit a224b48

Browse files
committed
Address review feedback
1 parent 74151fc commit a224b48

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

utils/build.ps1

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -646,30 +646,26 @@ function Invoke-BuildStep {
646646

647647
$SplatArgs = @{}
648648
if ($RemainingArgs) {
649-
$i = 0
650-
while ($i -lt $RemainingArgs.Count) {
651-
$Arg = $RemainingArgs[$i]
649+
$enumerator = $RemainingArgs.GetEnumerator()
650+
while ($enumerator.MoveNext()) {
651+
$Arg = $enumerator.Current
652652
if ($Arg -is [Hashtable]) {
653653
$SplatArgs += $Arg
654-
$i++
655654
} elseif ($Arg -is [string] -and $Arg.StartsWith('-')) {
656655
$ParamName = $Arg.TrimStart('-')
657-
658-
# Check if the next argument is a value for this parameter
659-
$HasNextArg = ($i -lt $RemainingArgs.Count - 1)
660-
if ($HasNextArg -and $RemainingArgs[$i + 1] -is [string] -and !$RemainingArgs[$i + 1].StartsWith('-')) {
661-
# This is a named parameter with a value
662-
$SplatArgs[$ParamName] = $RemainingArgs[$i + 1]
663-
$i += 2
664-
} else {
665-
# This is a switch parameter (flag)
666-
$SplatArgs[$ParamName] = $true
667-
$i++
656+
$HasNextArg = $RemainingArgs.IndexOf($Arg) -lt ($RemainingArgs.Count - 1)
657+
if ($HasNextArg) {
658+
$NextArg = $RemainingArgs[$RemainingArgs.IndexOf($Arg) + 1]
659+
if ($NextArg -is [string] -and !$NextArg.StartsWith('-')) {
660+
$SplatArgs[$ParamName] = $NextArg
661+
$enumerator.MoveNext() # Skip NextArg
662+
continue
663+
}
668664
}
665+
# Must be a flag.
666+
$SplatArgs[$ParamName] = $true
669667
} else {
670-
# Handle positional parameter
671668
throw "Positional parameter '$Arg' found. The Invoke-BuildStep function only supports named parameters after the required Name and Platform parameters."
672-
$i++
673669
}
674670
}
675671
}

0 commit comments

Comments
 (0)