Skip to content

Commit 5796e2b

Browse files
author
Github Actions
committed
Refactor Invoke-ExpressionWithLogging function in PSBuild module to allow pipeline input for ScriptBlock parameter. Improved clarity by adding a conditional check before displaying and executing the script block.
1 parent 5ac1abe commit 5796e2b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

scripts/PSBuild.psm1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,19 +1552,21 @@ function Invoke-ExpressionWithLogging {
15521552
#>
15531553
[CmdletBinding()]
15541554
param (
1555-
[Parameter(Mandatory=$true, Position=0)]
1555+
[Parameter(ValueFromPipeline=$true)]
15561556
[scriptblock]$ScriptBlock,
15571557
[Parameter()]
15581558
[AllowEmptyCollection()]
15591559
[string[]]$Tags = @("Invoke-ExpressionWithLogging")
15601560
)
15611561

1562-
# Display the expression
1563-
Write-Information -MessageData $ScriptBlock -Tags $Tags
1562+
if ($ScriptBlock) {
1563+
# Display the expression
1564+
Write-Information -MessageData $ScriptBlock -Tags $Tags
15641565

1565-
# Execute the expression and return its result
1566-
& $ScriptBlock | ForEach-Object {
1567-
Write-Output $_
1566+
# Execute the expression and return its result
1567+
& $ScriptBlock | ForEach-Object {
1568+
Write-Output $_
1569+
}
15681570
}
15691571
}
15701572

0 commit comments

Comments
 (0)