Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command/NewMarkdownHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected override void EndProcessing()
{
CreateModulePage = WithModulePage,
DoubleDashList = false,
ExcludeDontShow = false,
ExcludeDontShow = true,
FwLink = HelpInfoUri,
HelpVersion = HelpVersion.ToString(),
Locale = Locale is null ? CultureInfo.CurrentCulture : new CultureInfo(Locale),
Expand Down
14 changes: 14 additions & 0 deletions src/Transform/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ protected IEnumerable<Parameter> 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);
Expand Down Expand Up @@ -365,6 +369,11 @@ protected IEnumerable<SyntaxItem> 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(
Expand All @@ -383,6 +392,11 @@ protected IEnumerable<SyntaxItem> 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,
Expand Down
26 changes: 26 additions & 0 deletions test/Pester/NewMarkdownHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
$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'
}
}
}
Loading