Skip to content

Commit 1624bf6

Browse files
committed
Add support for named arguments in Invoke-BuildStep
1 parent 2d6f05b commit 1624bf6

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
@@ -637,21 +637,39 @@ function Invoke-BuildStep {
637637
[Parameter(Position=1, Mandatory)]
638638
[Hashtable] $Platform,
639639
[Parameter(ValueFromRemainingArguments)]
640-
$RemainingArgs
640+
[Object[]] $RemainingArgs
641641
)
642642

643643
if ($Summary) {
644644
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()
645645
}
646646

647647
$SplatArgs = @{}
648-
foreach ($Arg in $RemainingArgs) {
649-
if ($Arg -is [Hashtable]) {
650-
$SplatArgs += $Arg
651-
} elseif ($Arg -is [string]) {
652-
$SplatArgs[$Arg.TrimStart('-')] = $true
653-
} else {
654-
throw "$Arg is unknown type: $($Arg.GetType())"
648+
if ($RemainingArgs) {
649+
$i = 0
650+
while ($i -lt $RemainingArgs.Count) {
651+
$Arg = $RemainingArgs[$i]
652+
if ($Arg -is [Hashtable]) {
653+
$SplatArgs += $Arg
654+
$i++
655+
} elseif ($Arg -is [string] -and $Arg.StartsWith('-')) {
656+
$paramName = $Arg.TrimStart('-')
657+
658+
# Check if the next argument is a value for this parameter
659+
if ($i -lt $RemainingArgs.Count - 1 -and ($RemainingArgs[$i + 1] -isnot [string] -or !$RemainingArgs[$i + 1].StartsWith('-'))) {
660+
# This is a named parameter with a value
661+
$SplatArgs[$paramName] = $RemainingArgs[$i + 1]
662+
$i += 2
663+
} else {
664+
# This is a switch parameter (flag)
665+
$SplatArgs[$paramName] = $true
666+
$i++
667+
}
668+
} else {
669+
# Handle positional parameter
670+
throw "Positional parameter '$Arg' found. The Invoke-BuildStep function only supports named parameters after the required Name and Platform parameters."
671+
$i++
672+
}
655673
}
656674
}
657675

@@ -662,6 +680,7 @@ function Invoke-BuildStep {
662680
}
663681
}
664682

683+
665684
enum Project {
666685
BuildTools
667686
RegsGen2

0 commit comments

Comments
 (0)