diff --git a/src/Command/NewMarkdownHelpCommand.cs b/src/Command/NewMarkdownHelpCommand.cs index e0327438..9591d635 100644 --- a/src/Command/NewMarkdownHelpCommand.cs +++ b/src/Command/NewMarkdownHelpCommand.cs @@ -63,6 +63,9 @@ public sealed class NewMarkdownHelpCommand : PSCmdlet [Parameter] public SwitchParameter AbbreviateParameterTypeName { get; set; } + [Parameter] + public SwitchParameter ExcludeDontShow { get; set; } + #endregion List cmdCollection = new(); @@ -132,7 +135,7 @@ protected override void EndProcessing() { CreateModulePage = WithModulePage, DoubleDashList = false, - ExcludeDontShow = false, + ExcludeDontShow = ExcludeDontShow, FwLink = HelpInfoUri, HelpVersion = HelpVersion.ToString(), Locale = Locale is null ? CultureInfo.CurrentCulture : new CultureInfo(Locale), diff --git a/src/Transform/TransformBase.cs b/src/Transform/TransformBase.cs index e1fa9b78..eb7f5068 100644 --- a/src/Transform/TransformBase.cs +++ b/src/Transform/TransformBase.cs @@ -212,6 +212,10 @@ protected IEnumerable GetParameters(CommandInfo cmdletInfo, dynamic? } var paramAttribInfo = GetParameterAtributeInfo(parameterMetadata.Value.Attributes); + if (Settings.ExcludeDontShow.GetValueOrDefault() && paramAttribInfo.DontShow) + { + continue; + } string typeName = GetParameterTypeName(parameterMetadata.Value.ParameterType); Parameter param = new(parameterMetadata.Value.Name, typeName); @@ -365,6 +369,11 @@ protected IEnumerable GetSyntaxItem(CommandInfo? cmdletInfo, dynamic // Take the positional parameters first, and order them by position. foreach (CommandParameterInfo paramInfo in parameterSetInfo.Parameters.Where(p => p.Position != int.MinValue).OrderBy(p => p.Position)) { + if (Settings.ExcludeDontShow.GetValueOrDefault() && GetParameterAtributeInfo(paramInfo.Attributes).DontShow) + { + continue; + } + if (IsNotCommonParameter(paramInfo.Name)) { syn.SyntaxParameters.Add( new SyntaxParameter( @@ -383,6 +392,11 @@ protected IEnumerable GetSyntaxItem(CommandInfo? cmdletInfo, dynamic // now take the named parameters. foreach (CommandParameterInfo paramInfo in parameterSetInfo.Parameters.Where(p => p.Position == int.MinValue)) { + if (Settings.ExcludeDontShow.GetValueOrDefault() && GetParameterAtributeInfo(paramInfo.Attributes).DontShow) + { + continue; + } + if (IsNotCommonParameter(paramInfo.Name)) { var sParm = new SyntaxParameter( paramInfo.Name, diff --git a/test/Pester/NewMarkdownHelp.Tests.ps1 b/test/Pester/NewMarkdownHelp.Tests.ps1 index cf5bb195..20e242be 100644 --- a/test/Pester/NewMarkdownHelp.Tests.ps1 +++ b/test/Pester/NewMarkdownHelp.Tests.ps1 @@ -657,4 +657,30 @@ Write-Host 'Hello World!' $file | Should -FileContentMatch 'Runs the command in a mode that only reports what would happen without performing the actions.' } } + + Context 'DontShow attribute tests' { + BeforeAll { + function global:Test-DontShowParameter { + [CmdletBinding()] + param ( + [string] $Public, + [Parameter(DontShow)] [string] $Hidden, + [Parameter(DontShow)] [string] $Break + ) + } + + $file = New-MarkdownCommandHelp -Command (Get-Command 'Test-DontShowParameter') -OutputFolder "$TestDrive/NewMarkDownHelp" -ExcludeDontShow + $commandHelp = Import-MarkdownCommandHelp $file + } + + It 'does not emit hidden parameters in markdown output' { + $file | Should -Not -FileContentMatch '### -Hidden' + $file | Should -Not -FileContentMatch '### -Break' + } + + It 'does not include hidden parameters in the command model' { + $commandHelp.Parameters.Name | Should -Be @('Public') + $commandHelp.Syntax[0].ToString() | Should -Not -Match 'Hidden|Break' + } + } }