Skip to content

Commit ffd067e

Browse files
BernieWhitevors
authored andcommitted
Fix New-MarkdownHelp to generate CommonParameters as required PowerShell/platyPS/#223 PowerShell/platyPS/#253 (#323)
1 parent 22bb5a0 commit ffd067e

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66
* Clean up trailing whitespace during markdown generation [#225](https://github.com/PowerShell/platyPS/issues/225)
77
* Preserve line breaks after headers when Update-MarkdownHelp is used [#319](https://github.com/PowerShell/platyPS/issues/319)
88
* MAML generation now pads example titles with dash (-) to improve readability [#119](https://github.com/PowerShell/platyPS/issues/119)
9+
* Fixed issue with New-MarkdownHelp preventing CommonParameter being added for advanced functions and workflows [#223](https://github.com/PowerShell/platyPS/issues/223) [#253](https://github.com/PowerShell/platyPS/issues/253)
910

1011
## 0.8.3
1112

src/Markdown.MAML/Renderer/Markdownv2Renderer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ private void AddParameters(MamlCommand command)
181181
AddWorkflowParameters();
182182
}
183183

184-
if (command.SupportCommonParameters)
184+
// Workflows always support CommonParameters
185+
if (command.SupportCommonParameters || command.IsWorkflow)
185186
{
186187
AddCommonParameters();
187188
}

src/platyPS/platyPS.psm1

+7-10
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ function GetMamlObject
20572057
{
20582058
Write-Verbose ("`tProcessing: " + $Command.Name)
20592059
$Help = Get-Help $Command.Name
2060-
# yeild
2060+
# yield
20612061
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help) -UseFullTypeName:$UseFullTypeName
20622062
}
20632063
}
@@ -2078,7 +2078,7 @@ function GetMamlObject
20782078
HelpFile = (Split-Path $MamlFile -Leaf)
20792079
}
20802080

2081-
# yeild
2081+
# yield
20822082
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UseHelpForParametersMetadata -UseFullTypeName:$UseFullTypeName
20832083
}
20842084
}
@@ -2616,18 +2616,15 @@ function ConvertPsObjectsToMamlModel
26162616
Write-Warning "[Markdown generation] Could not find parameter object for $ParameterName in command $($Command.Name)"
26172617
}
26182618
}
2619-
2620-
# handle CommonParameters and CommonWorkflowParameters
2621-
if ($Command.CommandType -eq 'Function' -and $Command.CmdletBinding -eq $false)
2622-
{
2623-
# this is a really weired case, it may never appear in real modules
2624-
$MamlCommandObject.SupportCommonParameters = $false
2625-
}
2626-
else
2619+
2620+
# Handle CommonParameters, default for MamlCommand is SupportCommonParameters = $true
2621+
if ($Command.CmdletBinding -eq $false)
26272622
{
2623+
# Remove CommonParameters by exception
26282624
$MamlCommandObject.SupportCommonParameters = $false
26292625
}
26302626

2627+
# Handle CommonWorkflowParameters
26312628
$MamlCommandObject.IsWorkflow = $IsWorkflow
26322629

26332630
#endregion

test/Pester/PlatyPs.Tests.ps1

+37-6
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,30 @@ Describe 'New-MarkdownHelp' {
6767

6868
}
6969

70+
function Get-AdvancedFn
71+
{
72+
[CmdletBinding()]
73+
param (
74+
75+
)
76+
}
77+
78+
function Get-SimpleFn
79+
{
80+
param (
81+
82+
)
83+
}
84+
7085
function Set-BBBB
7186
{
7287

7388
}
7489

90+
Workflow FromCommandWorkflow {
91+
92+
}
93+
7594
# Set-Alias and New-Alias provide two different results
7695
# when `Get-Command -module Foo` is used to list commands.
7796
Set-Alias aaaaalias Get-AAAA
@@ -82,7 +101,7 @@ Describe 'New-MarkdownHelp' {
82101
Export-ModuleMember -Alias Fork-AAAA
83102
Export-ModuleMember -Alias aaaaalias
84103
Export-ModuleMember -Alias bbbbalias
85-
Export-ModuleMember -Function Get-AAAA
104+
Export-ModuleMember -Function 'Get-AAAA','Get-AdvancedFn','Get-SimpleFn','FromCommandWorkflow'
86105

87106
} | Import-Module -Force
88107

@@ -94,9 +113,21 @@ Describe 'New-MarkdownHelp' {
94113
}
95114

96115
It 'generates markdown files only for exported functions' {
97-
($files | Measure-Object).Count | Should Be 1
98-
$files.Name | Should Be 'Get-AAAA.md'
99-
}
116+
($files | Measure-Object).Count | Should Be 4
117+
$files.Name | Should -BeIn 'Get-AAAA.md','Get-AdvancedFn.md','Get-SimpleFn.md','FromCommandWorkflow.md'
118+
}
119+
120+
It 'generates markdown that includes CommonParameters in advanced functions' {
121+
($files | Where-Object -FilterScript { $_.Name -eq 'Get-AdvancedFn.md' }).FullName | Should -FileContentMatch '### CommonParameters'
122+
}
123+
124+
It 'generates markdown that excludes CommonParameters from simple functions' {
125+
($files | Where-Object -FilterScript { $_.Name -eq 'Get-SimpleFn.md' }).FullName | Should -FileContentMatch -Not '### CommonParameters'
126+
}
127+
128+
It 'generates markdown for workflows with CommonParameters' {
129+
($files | Where-Object -FilterScript { $_.Name -eq 'FromCommandWorkflow.md' }).FullName | Should -FileContentMatch '### CommonParameters'
130+
}
100131
}
101132

102133
Context 'from command' {
@@ -410,7 +441,7 @@ Type: System.Management.Automation.SwitchParameter
410441
411442
'@
412443
$expectedSyntax = normalizeEnds @'
413-
Get-Alpha [-WhatIf] [[-CCC] <String>] [[-ddd] <Int32>]
444+
Get-Alpha [-WhatIf] [[-CCC] <String>] [[-ddd] <Int32>] [<CommonParameters>]
414445
415446
'@
416447

@@ -428,7 +459,7 @@ Type: SwitchParameter
428459
429460
'@
430461
$expectedSyntax = normalizeEnds @'
431-
Get-Alpha [-WhatIf] [[-CCC] <String>] [[-ddd] <Int32>]
462+
Get-Alpha [-WhatIf] [[-CCC] <String>] [[-ddd] <Int32>] [<CommonParameters>]
432463
433464
'@
434465

0 commit comments

Comments
 (0)