Skip to content

Commit 485c932

Browse files
author
Github Actions
committed
Add Command parameter to Invoke-ExpressionWithLogging function in PSBuild module to allow execution of string commands as script blocks. Enhanced parameter handling and documentation for clarity.
1 parent 5796e2b commit 485c932

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

scripts/PSBuild.psm1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,8 @@ function Invoke-ExpressionWithLogging {
15421542
Invokes an expression and logs the result to the console.
15431543
.PARAMETER ScriptBlock
15441544
The script block to execute.
1545+
.PARAMETER Command
1546+
A string command to execute, which will be converted to a script block.
15451547
.PARAMETER Tags
15461548
Optional tags to include in the logging output for filtering and organization.
15471549
.OUTPUTS
@@ -1552,20 +1554,31 @@ function Invoke-ExpressionWithLogging {
15521554
#>
15531555
[CmdletBinding()]
15541556
param (
1555-
[Parameter(ValueFromPipeline=$true)]
1557+
[Parameter(ValueFromPipeline=$true, ParameterSetName="ScriptBlock")]
15561558
[scriptblock]$ScriptBlock,
1559+
1560+
[Parameter(ValueFromPipeline=$true, ParameterSetName="Command")]
1561+
[string]$Command,
1562+
15571563
[Parameter()]
15581564
[AllowEmptyCollection()]
15591565
[string[]]$Tags = @("Invoke-ExpressionWithLogging")
15601566
)
15611567

1562-
if ($ScriptBlock) {
1563-
# Display the expression
1564-
Write-Information -MessageData $ScriptBlock -Tags $Tags
1568+
process {
1569+
# Convert command string to scriptblock if needed
1570+
if ($PSCmdlet.ParameterSetName -eq "Command" -and -not [string]::IsNullOrWhiteSpace($Command)) {
1571+
$ScriptBlock = [scriptblock]::Create($Command)
1572+
}
1573+
1574+
if ($ScriptBlock) {
1575+
# Display the expression
1576+
Write-Information -MessageData $ScriptBlock -Tags $Tags
15651577

1566-
# Execute the expression and return its result
1567-
& $ScriptBlock | ForEach-Object {
1568-
Write-Output $_
1578+
# Execute the expression and return its result
1579+
& $ScriptBlock | ForEach-Object {
1580+
Write-Output $_
1581+
}
15691582
}
15701583
}
15711584
}

0 commit comments

Comments
 (0)