Skip to content

Commit 843f322

Browse files
author
Sergei Vorobev
committed
Handle HelpMessage attribute for parameters correctly
1 parent 3f25d00 commit 843f322

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

src/platyPS/platyPS.psm1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,17 @@ function ConvertPsObjectsToMamlModel
15581558

15591559
if ($HelpEntry.description)
15601560
{
1561-
$ParameterObject.Description = $HelpEntry.description.text | AddLineBreaksForParagraphs
1561+
if ($HelpEntry.description.text)
1562+
{
1563+
$ParameterObject.Description = $HelpEntry.description.text | AddLineBreaksForParagraphs
1564+
}
1565+
else
1566+
{
1567+
# this case happens, when there is HelpMessage in 'Parameter' attribute,
1568+
# but there is no maml or comment-based help.
1569+
# then help engine put string outside of 'text' property
1570+
$ParameterObject.Description = $HelpEntry.description | AddLineBreaksForParagraphs
1571+
}
15621572
}
15631573

15641574
$syntaxParam = $Help.syntax.syntaxItem.parameter | ? {$_.Name -eq $Parameter.Name} | Select -First 1

test/Pester/PlatyPs.Tests.ps1

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,95 @@ Describe 'New-MarkdownHelp' {
8686
}
8787
}
8888

89-
Context 'Generated markdown features' {
89+
Context 'Generated markdown features: comment-based help' {
9090
function global:Test-PlatyPSFunction
9191
{
92+
# comment-based help template from https://technet.microsoft.com/en-us/library/hh847834.aspx
93+
94+
<#
95+
.SYNOPSIS
96+
Adds a file name extension to a supplied name.
97+
98+
.DESCRIPTION
99+
Adds a file name extension to a supplied name.
100+
Takes any strings for the file name or extension.
101+
102+
.PARAMETER Second
103+
Second parameter help description
104+
105+
.OUTPUTS
106+
System.String. Add-Extension returns a string with the extension or file name.
107+
108+
.EXAMPLE
109+
C:\PS> Test-PlatyPSFunction "File"
110+
File.txt
111+
112+
.EXAMPLE
113+
C:\PS> Test-PlatyPSFunction "File" -First "doc"
114+
File.doc
115+
116+
.LINK
117+
http://www.fabrikam.com/extension.html
118+
119+
.LINK
120+
Set-Item
121+
#>
122+
92123
param(
93124
[Switch]$Common,
94-
[Parameter(ParameterSetName="First")]
125+
[Parameter(ParameterSetName="First", HelpMessage = 'First parameter help description')]
95126
[string]$First,
96127
[Parameter(ParameterSetName="Second")]
97128
[string]$Second
98129
)
99130
}
100131

101-
It 'generate markdown with correct parameter set names' {
102-
$file = New-MarkdownHelp -Command Test-PlatyPSFunction -OutputFolder TestDrive:\testAll -Force
103-
$content = cat $file
132+
$file = New-MarkdownHelp -Command Test-PlatyPSFunction -OutputFolder TestDrive:\testAll1 -Force
133+
$content = cat $file
134+
135+
It 'generates markdown with correct parameter set names' {
104136
($content | ? {$_ -eq 'Parameter Sets: (All)'} | measure).Count | Should Be 1
105137
($content | ? {$_ -eq 'Parameter Sets: First'} | measure).Count | Should Be 1
106138
($content | ? {$_ -eq 'Parameter Sets: Second'} | measure).Count | Should Be 1
107139
}
140+
141+
It 'generates markdown with correct help description specified by HelpMessage attribute' {
142+
($content | ? {$_ -eq 'First parameter help description'} | measure).Count | Should Be 1
143+
}
144+
145+
It 'generates markdown with correct help description specified by comment-based help' {
146+
($content | ? {$_ -eq 'Second parameter help description'} | measure).Count | Should Be 1
147+
}
148+
149+
It 'generates markdown with placeholder for parameter with no description' {
150+
($content | ? {$_ -eq '{{Fill Common Description}}'} | measure).Count | Should Be 1
151+
}
152+
}
153+
154+
Context 'Generated markdown features: no comment-based help' {
155+
function global:Test-PlatyPSFunction
156+
{
157+
# there is a help-engine behavior difference for functions with comment-based help (or maml help)
158+
# and no-comment based help, we test both
159+
param(
160+
[Switch]$Common,
161+
[Parameter(ParameterSetName="First", HelpMessage = 'First parameter help description')]
162+
[string]$First,
163+
[Parameter(ParameterSetName="Second")]
164+
[string]$Second
165+
)
166+
}
167+
168+
$file = New-MarkdownHelp -Command Test-PlatyPSFunction -OutputFolder TestDrive:\testAll2 -Force
169+
$content = cat $file
170+
171+
It 'generates markdown with correct help description specified by HelpMessage attribute' {
172+
($content | ? {$_ -eq 'First parameter help description'} | measure).Count | Should Be 1
173+
}
174+
175+
It 'generates markdown with placeholder for parameter with no description' {
176+
($content | ? {$_ -eq '{{Fill Common Description}}'} | measure).Count | Should Be 1
177+
}
108178
}
109179

110180
Context 'Dynamic parameters' {

0 commit comments

Comments
 (0)