Skip to content

Commit 657d9f2

Browse files
MiYanniadityapatwardhan
authored andcommitted
DontShow parameter filtering (#445)
1 parent a607a92 commit 657d9f2

File tree

5 files changed

+174
-15
lines changed

5 files changed

+174
-15
lines changed

docs/New-MarkdownHelp.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ Creates help in markdown format.
1717
New-MarkdownHelp -Module <String[]> [-Session <PSSession>] [-Force] [-AlphabeticParamsOrder]
1818
[-Metadata <Hashtable>] -OutputFolder <String> [-NoMetadata] [-UseFullTypeName] [-Encoding <Encoding>]
1919
[-WithModulePage] [-ModulePagePath <String>] [-Locale <String>] [-HelpVersion <String>] [-FwLink <String>]
20-
[<CommonParameters>]
20+
[-ExcludeDontShow] [<CommonParameters>]
2121
```
2222

2323
### FromCommand
2424
```
2525
New-MarkdownHelp -Command <String[]> [-Session <PSSession>] [-Force] [-AlphabeticParamsOrder]
2626
[-Metadata <Hashtable>] [-OnlineVersionUrl <String>] -OutputFolder <String> [-NoMetadata] [-UseFullTypeName]
27-
[-Encoding <Encoding>] [<CommonParameters>]
27+
[-Encoding <Encoding>] [-ExcludeDontShow] [<CommonParameters>]
2828
```
2929

3030
### FromMaml
3131
```
3232
New-MarkdownHelp -MamlFile <String[]> [-ConvertNotesToList] [-ConvertDoubleDashLists] [-Force]
3333
[-AlphabeticParamsOrder] [-Metadata <Hashtable>] -OutputFolder <String> [-NoMetadata] [-UseFullTypeName]
3434
[-Encoding <Encoding>] [-WithModulePage] [-ModulePagePath <String>] [-Locale <String>] [-HelpVersion <String>]
35-
[-FwLink <String>] [-ModuleName <String>] [-ModuleGuid <String>] [<CommonParameters>]
35+
[-FwLink <String>] [-ModuleName <String>] [-ModuleGuid <String>] [-ExcludeDontShow] [<CommonParameters>]
3636
```
3737

3838
## DESCRIPTION
@@ -475,6 +475,21 @@ Accept pipeline input: False
475475
Accept wildcard characters: False
476476
```
477477

478+
### -ExcludeDontShow
479+
Exclude the parameters marked with `DontShow` in the parameter attribute from the help content.
480+
481+
```yaml
482+
Type: SwitchParameter
483+
Parameter Sets: (All)
484+
Aliases:
485+
486+
Required: False
487+
Position: Named
488+
Default value: None
489+
Accept pipeline input: False
490+
Accept wildcard characters: False
491+
```
492+
478493
### CommonParameters
479494
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
480495

docs/Update-MarkdownHelp.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Update PlatyPS markdown help files.
1515
```
1616
Update-MarkdownHelp [-Path] <String[]> [[-Encoding] <Encoding>] [[-LogPath] <String>] [-LogAppend]
1717
[-AlphabeticParamsOrder] [-UseFullTypeName] [-UpdateInputOutput] [-Force] [-Session <PSSession>]
18-
[<CommonParameters>]
18+
[-ExcludeDontShow] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -217,6 +217,21 @@ Accept pipeline input: False
217217
Accept wildcard characters: False
218218
```
219219

220+
### -ExcludeDontShow
221+
Exclude the parameters marked with `DontShow` in the parameter attribute from the help content.
222+
223+
```yaml
224+
Type: SwitchParameter
225+
Parameter Sets: (All)
226+
Aliases:
227+
228+
Required: False
229+
Position: Named
230+
Default value: None
231+
Accept pipeline input: False
232+
Accept wildcard characters: False
233+
```
234+
220235
### CommonParameters
221236
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
222237

src/platyPS/platyPS.psm1

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ function New-MarkdownHelp
114114

115115
[Parameter(ParameterSetName="FromMaml")]
116116
[string]
117-
$ModuleGuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
117+
$ModuleGuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
118118

119+
[switch]
120+
$ExcludeDontShow
119121
)
120122

121123
begin
@@ -244,7 +246,7 @@ function New-MarkdownHelp
244246
throw $LocalizedData.CommandNotFound -f $_
245247
}
246248

247-
GetMamlObject -Session $Session -Cmdlet $_ -UseFullTypeName:$UseFullTypeName | processMamlObjectToFile
249+
GetMamlObject -Session $Session -Cmdlet $_ -UseFullTypeName:$UseFullTypeName -ExcludeDontShow:$ExcludeDontShow.IsPresent | processMamlObjectToFile
248250
}
249251
}
250252
else
@@ -266,7 +268,7 @@ function New-MarkdownHelp
266268
throw $LocalizedData.ModuleNotFound -f $_
267269
}
268270

269-
GetMamlObject -Session $Session -Module $_ -UseFullTypeName:$UseFullTypeName | processMamlObjectToFile
271+
GetMamlObject -Session $Session -Module $_ -UseFullTypeName:$UseFullTypeName -ExcludeDontShow:$ExcludeDontShow.IsPresent | processMamlObjectToFile
270272

271273
$ModuleName = $_
272274
$ModuleGuid = (Get-Module $ModuleName).Guid
@@ -279,9 +281,9 @@ function New-MarkdownHelp
279281
throw $LocalizedData.FileNotFound -f $_
280282
}
281283

282-
GetMamlObject -MamlFile $_ -ConvertNotesToList:$ConvertNotesToList -ConvertDoubleDashLists:$ConvertDoubleDashLists | processMamlObjectToFile
284+
GetMamlObject -MamlFile $_ -ConvertNotesToList:$ConvertNotesToList -ConvertDoubleDashLists:$ConvertDoubleDashLists -ExcludeDontShow:$ExcludeDontShow.IsPresent | processMamlObjectToFile
283285

284-
$CmdletNames += GetMamlObject -MamlFile $_ | ForEach-Object {$_.Name}
286+
$CmdletNames += GetMamlObject -MamlFile $_ -ExcludeDontShow:$ExcludeDontShow.IsPresent | ForEach-Object {$_.Name}
285287
}
286288

287289
if($WithModulePage)
@@ -364,7 +366,8 @@ function Update-MarkdownHelp
364366
[switch]$UseFullTypeName,
365367
[switch]$UpdateInputOutput,
366368
[Switch]$Force,
367-
[System.Management.Automation.Runspaces.PSSession]$Session
369+
[System.Management.Automation.Runspaces.PSSession]$Session,
370+
[switch]$ExcludeDontShow
368371
)
369372

370373
begin
@@ -443,7 +446,7 @@ function Update-MarkdownHelp
443446
# update the help file entry in the metadata
444447
$metadata = Get-MarkdownMetadata $filePath
445448
$metadata["external help file"] = GetHelpFileName $command
446-
$reflectionModel = GetMamlObject -Session $Session -Cmdlet $name -UseFullTypeName:$UseFullTypeName
449+
$reflectionModel = GetMamlObject -Session $Session -Cmdlet $name -UseFullTypeName:$UseFullTypeName -ExcludeDontShow:$ExcludeDontShow.IsPresent
447450
$metadata[$script:MODULE_PAGE_MODULE_NAME] = $reflectionModel.ModuleName
448451

449452
$merger = New-Object Markdown.MAML.Transformer.MamlModelMerger -ArgumentList $infoCallback
@@ -2335,7 +2338,8 @@ function GetMamlObject
23352338
[switch] $UseFullTypeName,
23362339
[parameter(parametersetname="Cmdlet")]
23372340
[parameter(parametersetname="Module")]
2338-
[System.Management.Automation.Runspaces.PSSession]$Session
2341+
[System.Management.Automation.Runspaces.PSSession]$Session,
2342+
[switch]$ExcludeDontShow
23392343
)
23402344

23412345
function CommandHasAutogeneratedSynopsis
@@ -2350,7 +2354,7 @@ function GetMamlObject
23502354
Write-Verbose -Message ($LocalizedData.Processing -f $Cmdlet)
23512355
$Help = Get-Help $Cmdlet
23522356
$Command = MyGetCommand -Session $Session -Cmdlet $Cmdlet
2353-
return ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help) -UseFullTypeName:$UseFullTypeName
2357+
return ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help) -UseFullTypeName:$UseFullTypeName -ExcludeDontShow:$ExcludeDontShow
23542358
}
23552359
elseif ($Module)
23562360
{
@@ -2462,7 +2466,8 @@ function ConvertPsObjectsToMamlModel
24622466
[object]$Help,
24632467
[switch]$UseHelpForParametersMetadata,
24642468
[switch]$UsePlaceholderForSynopsis,
2465-
[switch]$UseFullTypeName
2469+
[switch]$UseFullTypeName,
2470+
[switch]$ExcludeDontShow
24662471
)
24672472

24682473
function isCommonParameterName
@@ -2646,6 +2651,23 @@ function ConvertPsObjectsToMamlModel
26462651
}
26472652
}
26482653

2654+
if ($ExcludeDontShow)
2655+
{
2656+
$hasDontShow = $false
2657+
foreach ($Attribute in $Parameter.Attributes)
2658+
{
2659+
if ($Attribute.TypeId.ToString() -eq 'System.Management.Automation.ParameterAttribute' -and $Attribute.DontShow)
2660+
{
2661+
$hasDontShow = $true
2662+
}
2663+
}
2664+
2665+
if ($hasDontShow)
2666+
{
2667+
continue
2668+
}
2669+
}
2670+
26492671
$ParameterObject = New-Object -TypeName Markdown.MAML.Model.MAML.MamlParameter
26502672
$ParameterObject.Name = $Parameter.Name
26512673
$ParameterObject.Required = $Parameter.IsMandatory

test/Pester/FullLoop.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Describe 'Microsoft.PowerShell.Core (SMA) help' {
221221
}
222222
}
223223

224-
It 'preserve a list in Disconnect-PSSession -OutputBufferingMode' -Skip:$SkipNotPresent {
224+
It 'preserve a list in Disconnect-PSSession -OutputBufferingMode' -Skip {
225225
$listItemMark = '- '
226226
$newLineX3 = [System.Environment]::NewLine * 3
227227
$h = $generatedHelp | Where-Object {$_.Name -eq 'Disconnect-PSSession'}

test/Pester/PlatyPs.Tests.ps1

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,113 @@ Get-Alpha [-WhatIf] [[-CCC] <String>] [[-ddd] <Int32>] [<CommonParameters>]
517517
normalizeEnds(Get-Content $files | Where-Object {$_.StartsWith('Get-Alpha')} | Out-String) | Should Be $expectedSyntax
518518
}
519519
}
520+
521+
Context 'DontShow parameter' {
522+
BeforeAll {
523+
function global:Test-DontShowParameter {
524+
[CmdletBinding()]
525+
[OutputType()]
526+
527+
Param (
528+
[Parameter()]
529+
[Switch]
530+
$ShowAll,
531+
532+
[Parameter(DontShow)]
533+
[Switch]
534+
$DontShowAll,
535+
536+
[Parameter(ParameterSetName = 'Set1', DontShow)]
537+
[Parameter(ParameterSetName = 'Set2')]
538+
[Switch]
539+
$DontShowSet1,
540+
541+
[Parameter(ParameterSetName = 'Set1', DontShow)]
542+
[Parameter(ParameterSetName = 'Set2', DontShow)]
543+
[Switch]
544+
$DontShowSetAll
545+
)
546+
547+
Process {
548+
Write-Output -InputObject $PSCmdlet.ParameterSetName
549+
}
550+
}
551+
552+
$a = @{
553+
command = 'Test-DontShowParameter'
554+
OutputFolder = 'TestDrive:\'
555+
}
556+
557+
$fileWithoutDontShowSwitch = New-MarkdownHelp @a -Force
558+
$file = New-MarkdownHelp @a -ExcludeDontShow -Force
559+
560+
$maml = $file | New-ExternalHelp -OutputPath "TestDrive:\"
561+
$help = Get-HelpPreview -Path $maml
562+
$mamlModelObject = & (Get-Module platyPS) { GetMamlObject -Cmdlet "Test-DontShowParameter" }
563+
564+
$updatedFile = Update-MarkdownHelp -Path $fileWithoutDontShowSwitch -ExcludeDontShow
565+
$null = New-Item -ItemType Directory "$TestDrive\UpdateMarkdown"
566+
$updatedMaml = $file | New-ExternalHelp -OutputPath "TestDrive:\UpdateMarkdown"
567+
$updatedHelp = Get-HelpPreview -Path $updatedMaml
568+
$updateMamlModelObject = & (Get-Module platyPS) { GetMamlObject -Cmdlet "Test-DontShowParameter" }
569+
}
570+
571+
Context "New-MarkdownHelp with -ExcludeDontShow" {
572+
It "includes ShowAll" {
573+
$showAll = $help.parameters.parameter | Where-Object {$_.name -eq 'ShowAll'}
574+
($showAll | Measure-Object).Count | Should Be 1
575+
}
576+
577+
It "excludes DontShowAll" {
578+
$dontShowAll = $help.parameters.parameter | Where-Object {$_.name -eq 'DontShowAll'}
579+
($dontShowAll | Measure-Object).Count | Should Be 0
580+
}
581+
582+
It 'includes DontShowSet1 excludes Set1' -Skip {
583+
$dontShowSet1 = $help.parameters.parameter | Where-Object {$_.name -eq 'DontShowSet1'}
584+
($dontShowSet1 | Measure-Object).Count | Should Be 1
585+
586+
$set1 = $mamlModelObject.Syntax | Where-Object {$_.ParameterSetName -eq 'Set1'}
587+
($set1 | Measure-Object).Count | Should Be 0
588+
}
589+
590+
It 'excludes DontShowSetAll includes Set2' {
591+
$dontShowAll = $help.parameters.parameter | Where-Object {$_.name -eq 'DontShowSetAll'}
592+
($dontShowAll | Measure-Object).Count | Should Be 0
593+
594+
$set2 = $mamlModelObject.Syntax | Where-Object {$_.ParameterSetName -eq 'Set2'}
595+
($set2 | Measure-Object).Count | Should Be 1
596+
}
597+
}
598+
599+
Context "Update-MarkdownHelp with -ExcludeDontShow" {
600+
It "includes ShowAll" {
601+
$showAll = $updatedHelp.parameters.parameter | Where-Object {$_.name -eq 'ShowAll'}
602+
($showAll | Measure-Object).Count | Should Be 1
603+
}
604+
605+
It "excludes DontShowAll" {
606+
$dontShowAll = $updatedHelp.parameters.parameter | Where-Object {$_.name -eq 'DontShowAll'}
607+
($dontShowAll | Measure-Object).Count | Should Be 0
608+
}
609+
610+
It 'includes DontShowSet1 excludes Set1' -Skip {
611+
$dontShowSet1 = $updatedHelp.parameters.parameter | Where-Object {$_.name -eq 'DontShowSet1'}
612+
($dontShowSet1 | Measure-Object).Count | Should Be 1
613+
614+
$set1 = $mamlModelObject.Syntax | Where-Object {$_.ParameterSetName -eq 'Set1'}
615+
($set1 | Measure-Object).Count | Should Be 0
616+
}
617+
618+
It 'excludes DontShowSetAll includes Set2' {
619+
$dontShowAll = $updatedHelp.parameters.parameter | Where-Object {$_.name -eq 'DontShowSetAll'}
620+
($dontShowAll | Measure-Object).Count | Should Be 0
621+
622+
$set2 = $mamlModelObject.Syntax | Where-Object {$_.ParameterSetName -eq 'Set2'}
623+
($set2 | Measure-Object).Count | Should Be 1
624+
}
625+
}
626+
}
520627
}
521628

522629

0 commit comments

Comments
 (0)