Skip to content

Commit 5960511

Browse files
committed
Fix output when parameters not found
1 parent 14df99e commit 5960511

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

PSModuleDevelopment/functions/utility/Show-PSMDSyntax.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898

9999
if (-not ($null -eq $inputParameterMatch)) {
100100
$inputParameterNames = $inputParameterMatch.Value.Trim("-", " ")
101+
Write-PSFMessage -Level Verbose -Message "All input parameters - $($inputParameterNames -join ",")" -Target ($inputParameterNames -join ",")
101102
}
102103
else {
103104
Write-PSFMessage -Level Host -Message "The function was unable to extract any parameters from the supplied command text. Please try again."
@@ -106,13 +107,17 @@
106107
}
107108

108109
$availableParameterNames = (Get-Command $commandName).Parameters.keys | Where-Object {$commonParameters -NotContains $_}
110+
Write-PSFMessage -Level Verbose -Message "Available parameters - $($availableParameterNames -join ",")" -Target ($availableParameterNames -join ",")
111+
109112
$inputParameterNotFound = $inputParameterNames | Where-Object {$availableParameterNames -NotContains $_}
110113

111-
$null = $sbParmsNotFound.AppendLine("Parameters that <c='em'>don't exists</c>")
112-
$inputParameterNotFound | ForEach-Object {
113-
$null = $sbParmsNotFound.AppendLine("<c='$colorParmsNotFound'>$($_)</c>")
114+
if ($inputParameterNotFound.Length -gt 0) {
115+
$null = $sbParmsNotFound.AppendLine("Parameters that <c='em'>don't exists</c>")
116+
$inputParameterNotFound | ForEach-Object {
117+
$null = $sbParmsNotFound.AppendLine("<c='$colorParmsNotFound'>$($_)</c>")
118+
}
114119
}
115-
120+
116121
foreach ($parmSet in (Get-Command $commandName).ParameterSets) {
117122
$sb = New-Object System.Text.StringBuilder
118123
$null = $sb.AppendLine("ParameterSet Name: <c='em'>$($parmSet.Name)</c> - Validated List")
@@ -193,7 +198,7 @@
193198
Default {}
194199
}
195200

196-
if ($sbParmsNotFound.Length -gt 0) {
201+
if ($sbParmsNotFound.ToString().Trim().Length -gt 0) {
197202
Write-PSFHostColor -String "$($sbParmsNotFound.ToString())"
198203
}
199204

0 commit comments

Comments
 (0)