Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4135,7 +4135,7 @@ .FORWARDHELPCATEGORY Cmdlet
${Examples},

[Parameter(ParameterSetName='Parameters', Mandatory=$true)]
[string]
[string[]]
${Parameter},

[string[]]
Expand Down
36 changes: 29 additions & 7 deletions src/System.Management.Automation/help/HelpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public SwitchParameter Examples
/// Support WildCard strings as supported by WildcardPattern class.
/// </remarks>
[Parameter(ParameterSetName = "Parameters", Mandatory = true)]
public string Parameter { set; get; }
public string[] Parameter { get; set; }

/// <summary>
/// Gets and sets list of Component's to search on.
Expand Down Expand Up @@ -433,15 +433,36 @@ private PSObject TransformView(PSObject originalHelpObject)
}

/// <summary>
/// Gets the parameter info for patterns identified Parameter property.
/// Gets the parameter info for patterns identified by Parameter property.
/// </summary>
/// <param name="helpInfo">HelpInfo object to look for the parameter.</param>
/// <returns>Array of parameter infos.</returns>
private PSObject[] GetParameterInfo(HelpInfo helpInfo)
{
List<PSObject> parameterInfosList = new List<PSObject>(Parameter.Length);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider moving Parameter != null checks to the method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this is necessary.


foreach (var parameter in Parameter)
{
foreach (var parameterInfo in helpInfo.GetParameter(parameter))
{
parameterInfosList.Add(parameterInfo);
}
}

return parameterInfosList.ToArray();
}

/// <summary>
/// Gets the parameter info for patterns identified by Parameter property.
/// Writes the parameter info(s) to the output stream. An error is thrown
/// if a parameter with a given pattern is not found.
/// </summary>
/// <param name="helpInfo">HelpInfo Object to look for the parameter.</param>
private void GetAndWriteParameterInfo(HelpInfo helpInfo)
{
s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name);
PSObject[] pInfos = helpInfo.GetParameter(Parameter);

PSObject[] pInfos = GetParameterInfo(helpInfo);

if ((pInfos == null) || (pInfos.Length == 0))
{
Expand Down Expand Up @@ -479,7 +500,7 @@ private void ValidateAndThrowIfError(HelpCategory cat)

if ((cat & supportedCategories) == 0)
{
if (!string.IsNullOrEmpty(Parameter))
if (Parameter != null)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please comment why we need the change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter is a string array now.

{
throw PSTraceSource.NewArgumentException("Parameter",
HelpErrors.ParamNotSupported, "-Parameter");
Expand Down Expand Up @@ -540,7 +561,7 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
// show inline help
if (showFullHelp)
{
if (!string.IsNullOrEmpty(Parameter))
if (Parameter != null)
{
GetAndWriteParameterInfo(helpInfo);
}
Expand All @@ -553,9 +574,10 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
}
else
{
if (!string.IsNullOrEmpty(Parameter))
if (Parameter != null)
{
PSObject[] pInfos = helpInfo.GetParameter(Parameter);
PSObject[] pInfos = GetParameterInfo(helpInfo);

if ((pInfos == null) || (pInfos.Length == 0))
{
return;
Expand Down
25 changes: 25 additions & 0 deletions test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,31 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin
}
}

Describe "Get-Help should accept arrays as the -Parameter parameter value" -Tags @('CI') {

BeforeAll {
$userHelpRoot = GetCurrentUserHelpRoot

## Clear all help from user scope.
Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse
UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'CurrentUser'

## Delete help from global scope if it exists.
$currentCulture = (Get-Culture).Name
$coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml'
if (Test-Path $coreHelpFilePath) {
Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue
}
}

It "Should return help objects for two parameters" {
$help = Get-Help -Name Get-Command -Parameter Verb, Noun
$help | Should -HaveCount 2
$help[0].Name | Should -BeExactly 'Verb'
$help[1].Name | Should -BeExactly 'Noun'
}
}

Describe "Help failure cases" -Tags Feature {
It "An error is returned for a topic that doesn't exist: <command>" -TestCases @(
@{ command = "help" },
Expand Down