Skip to content

Commit cf2a0ee

Browse files
committed
Add support for named arguments in Invoke-BuildStep
1 parent 835885d commit cf2a0ee

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

utils/build.ps1

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,21 +583,39 @@ function Invoke-BuildStep {
583583
[Parameter(Position=1, Mandatory)]
584584
[Hashtable] $Platform,
585585
[Parameter(ValueFromRemainingArguments)]
586-
$RemainingArgs
586+
[Object[]] $RemainingArgs
587587
)
588588

589589
if ($Summary) {
590590
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
591591
}
592592

593593
$SplatArgs = @{}
594-
foreach ($Arg in $RemainingArgs) {
595-
if ($Arg -is [Hashtable]) {
596-
$SplatArgs += $Arg
597-
} elseif ($Arg -is [string]) {
598-
$SplatArgs[$Arg.TrimStart('-')] = $true
599-
} else {
600-
throw "$Arg is unknown type: $($Arg.GetType())"
594+
if ($RemainingArgs) {
595+
$i = 0
596+
while ($i -lt $RemainingArgs.Count) {
597+
$Arg = $RemainingArgs[$i]
598+
if ($Arg -is [Hashtable]) {
599+
$SplatArgs += $Arg
600+
$i++
601+
} elseif ($Arg -is [string] -and $Arg.StartsWith('-')) {
602+
$paramName = $Arg.TrimStart('-')
603+
604+
# Check if the next argument is a value for this parameter
605+
if ($i -lt $RemainingArgs.Count - 1 -and ($RemainingArgs[$i + 1] -isnot [string] -or !$RemainingArgs[$i + 1].StartsWith('-'))) {
606+
# This is a named parameter with a value
607+
$SplatArgs[$paramName] = $RemainingArgs[$i + 1]
608+
$i += 2
609+
} else {
610+
# This is a switch parameter (flag)
611+
$SplatArgs[$paramName] = $true
612+
$i++
613+
}
614+
} else {
615+
# Handle positional parameter
616+
throw "Positional parameter '$Arg' found. The Invoke-BuildStep function only supports named parameters after the required Name and Platform parameters."
617+
$i++
618+
}
601619
}
602620
}
603621

@@ -608,6 +626,7 @@ function Invoke-BuildStep {
608626
}
609627
}
610628

629+
611630
enum Project {
612631
BuildTools
613632
RegsGen2

0 commit comments

Comments
 (0)