Fix Get-Help not properly displaying if parameter supports wildcards (#13353)

This commit is contained in:
Thomas Nieto
2020-08-11 10:20:45 -07:00
committed by GitHub
parent d8f8f0a8bc
commit 46efd38ef5
3 changed files with 56 additions and 0 deletions
@@ -525,6 +525,9 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.AddText(HelpDisplayStrings.ParameterIsDynamic)
.AddPropertyExpressionBinding(@"isDynamic")
.AddNewline()
.AddText(HelpDisplayStrings.AcceptsWildCardCharacters)
.AddPropertyExpressionBinding(@"globbing")
.AddNewline()
.AddNewline()
.EndFrame()
.EndEntry()
@@ -711,6 +714,9 @@ else { '-{0}{1} ' }) -f $_.Name, $parameterValue")
.AddText(HelpDisplayStrings.ParameterIsDynamic)
.AddPropertyExpressionBinding(@"isDynamic")
.AddNewline()
.AddText(HelpDisplayStrings.AcceptsWildCardCharacters)
.AddPropertyExpressionBinding(@"globbing")
.AddNewline()
.AddNewline()
.EndFrame()
.EndEntry()
@@ -423,6 +423,7 @@ namespace System.Management.Automation.Help
obj.Properties.Add(new PSNoteProperty("description", string.Empty));
obj.Properties.Add(new PSNoteProperty("position", string.Empty));
obj.Properties.Add(new PSNoteProperty("aliases", string.Empty));
obj.Properties.Add(new PSNoteProperty("globbing", string.Empty));
}
else
{
@@ -442,6 +443,7 @@ namespace System.Management.Automation.Help
obj.Properties.Add(new PSNoteProperty("required", CultureInfo.CurrentCulture.TextInfo.ToLower(paramAttribute.Mandatory.ToString())));
obj.Properties.Add(new PSNoteProperty("pipelineInput", GetPipelineInputString(paramAttribute)));
obj.Properties.Add(new PSNoteProperty("isDynamic", CultureInfo.CurrentCulture.TextInfo.ToLower(dynamic.ToString())));
AddParameterGlobbingProperties(obj, attributes);
if (paramAttribute.ParameterSetName.Equals(ParameterAttribute.AllParameterSets, StringComparison.OrdinalIgnoreCase))
{
@@ -517,6 +519,27 @@ namespace System.Management.Automation.Help
}
}
/// <summary>
/// Adds the globbing properties.
/// </summary>
/// <param name="obj">HelpInfo object.</param>
/// <param name="attributes">The attributes of the parameter (needed to look for PSTypeName).</param>
private static void AddParameterGlobbingProperties(PSObject obj, IEnumerable<Attribute> attributes)
{
bool globbing = false;
foreach (var attrib in attributes)
{
if (attrib is SupportsWildcardsAttribute)
{
globbing = true;
break;
}
}
obj.Properties.Add(new PSNoteProperty("globbing", CultureInfo.CurrentCulture.TextInfo.ToLower(globbing.ToString())));
}
/// <summary>
/// Adds the parameterType properties.
/// </summary>
@@ -614,6 +614,33 @@ Describe 'get-help other tests' -Tags "CI" {
It '$x.Parameters.parameter[2].defaultValue' { $x.Parameters.parameter[2].defaultValue | Should -BeExactly 'parameter is mandatory' }
}
Context 'get-help helpFunc14' {
function helpFunc14
{
param(
[SupportsWildcards()]
$p1
)
}
$x = Get-Help helpFunc14
It '$x.Parameters.parameter[0].globbing' { $x.Parameters.parameter[0].globbing | Should -BeExactly 'true' }
}
Context 'get-help helpFunc15' {
function helpFunc15
{
param(
$p1
)
}
$x = Get-Help helpFunc15
It '$x.Parameters.parameter[0].globbing' { $x.Parameters.parameter[0].globbing | Should -BeExactly 'false' }
}
Context 'get-help -Examples prompt string should have trailing space' {
function foo {
<#