From 7875ad482a961c251726a8edca3f6ced39ab01c4 Mon Sep 17 00:00:00 2001 From: sethvs Date: Wed, 12 Dec 2018 15:13:03 +0300 Subject: [PATCH 01/10] Get-Help cmdlet -Parameter parameter accepts string array. --- .../engine/InitialSessionState.cs | 2 +- .../help/HelpCommands.cs | 38 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index f86b2869e5a..248f165fba4 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4094,7 +4094,7 @@ .FORWARDHELPCATEGORY Cmdlet ${Examples}, [Parameter(ParameterSetName='Parameters', Mandatory=$true)] - [string] + [string[]] ${Parameter}, [string[]] diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index b9a40818b51..504491b1fc4 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -157,7 +157,12 @@ public SwitchParameter Examples /// Support WildCard strings as supported by WildcardPattern class. /// [Parameter(ParameterSetName = "Parameters", Mandatory = true)] - public string Parameter { set; get; } + public string[] Parameter + { + get => _parameters; + set => _parameters = value; + } + private string[] _parameters; /// /// Gets and sets list of Component's to search on. @@ -438,7 +443,17 @@ private PSObject TransformView(PSObject originalHelpObject) private void GetAndWriteParameterInfo(HelpInfo helpInfo) { s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name); - PSObject[] pInfos = helpInfo.GetParameter(Parameter); + List _pInfos = new List(_parameters.Length); + + foreach (var _parameter in _parameters) + { + foreach (var _pInfo in helpInfo.GetParameter(_parameter)) + { + _pInfos.Add(_pInfo); + } + } + + PSObject[] pInfos = _pInfos.ToArray(); if ((pInfos == null) || (pInfos.Length == 0)) { @@ -476,7 +491,7 @@ private void ValidateAndThrowIfError(HelpCategory cat) if ((cat & supportedCategories) == 0) { - if (!string.IsNullOrEmpty(Parameter)) + if (_parameters != null) { throw PSTraceSource.NewArgumentException("Parameter", HelpErrors.ParamNotSupported, "-Parameter"); @@ -537,7 +552,7 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) // show inline help if (showFullHelp) { - if (!string.IsNullOrEmpty(Parameter)) + if (_parameters != null) { GetAndWriteParameterInfo(helpInfo); } @@ -550,9 +565,20 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) } else { - if (!string.IsNullOrEmpty(Parameter)) + if (_parameters != null) { - PSObject[] pInfos = helpInfo.GetParameter(Parameter); + List _pInfos = new List(_parameters.Length); + + foreach (var _parameter in _parameters) + { + foreach (var _pInfo in helpInfo.GetParameter(_parameter)) + { + _pInfos.Add(_pInfo); + } + } + + PSObject[] pInfos = _pInfos.ToArray(); + if ((pInfos == null) || (pInfos.Length == 0)) { return; From c36ba8388cee889d76f5baf80742cd9ae38418f7 Mon Sep 17 00:00:00 2001 From: sethvs Date: Wed, 12 Dec 2018 15:50:03 +0300 Subject: [PATCH 02/10] Fix variable names. --- .../help/HelpCommands.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 504491b1fc4..542b608ce6d 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -443,17 +443,17 @@ private PSObject TransformView(PSObject originalHelpObject) private void GetAndWriteParameterInfo(HelpInfo helpInfo) { s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name); - List _pInfos = new List(_parameters.Length); + List pInfosList = new List(_parameters.Length); - foreach (var _parameter in _parameters) + foreach (var parameter in _parameters) { - foreach (var _pInfo in helpInfo.GetParameter(_parameter)) + foreach (var pInfo in helpInfo.GetParameter(parameter)) { - _pInfos.Add(_pInfo); + pInfosList.Add(pInfo); } } - PSObject[] pInfos = _pInfos.ToArray(); + PSObject[] pInfos = pInfosList.ToArray(); if ((pInfos == null) || (pInfos.Length == 0)) { @@ -567,17 +567,17 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) { if (_parameters != null) { - List _pInfos = new List(_parameters.Length); + List pInfosList = new List(_parameters.Length); - foreach (var _parameter in _parameters) + foreach (var parameter in _parameters) { - foreach (var _pInfo in helpInfo.GetParameter(_parameter)) + foreach (var pInfo in helpInfo.GetParameter(parameter)) { - _pInfos.Add(_pInfo); + pInfosList.Add(pInfo); } } - PSObject[] pInfos = _pInfos.ToArray(); + PSObject[] pInfos = pInfosList.ToArray(); if ((pInfos == null) || (pInfos.Length == 0)) { From 592ab626eaa86ddd7b3bb423f2b1e32bd7410fc5 Mon Sep 17 00:00:00 2001 From: sethvs Date: Thu, 13 Dec 2018 10:50:39 +0300 Subject: [PATCH 03/10] Use public string[] Parameter --- .../help/HelpCommands.cs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 542b608ce6d..3cb2a2e6c94 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -157,12 +157,7 @@ public SwitchParameter Examples /// Support WildCard strings as supported by WildcardPattern class. /// [Parameter(ParameterSetName = "Parameters", Mandatory = true)] - public string[] Parameter - { - get => _parameters; - set => _parameters = value; - } - private string[] _parameters; + public string[] Parameter { get; set; } /// /// Gets and sets list of Component's to search on. @@ -443,9 +438,9 @@ private PSObject TransformView(PSObject originalHelpObject) private void GetAndWriteParameterInfo(HelpInfo helpInfo) { s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name); - List pInfosList = new List(_parameters.Length); + List pInfosList = new List(Parameter.Length); - foreach (var parameter in _parameters) + foreach (var parameter in Parameter) { foreach (var pInfo in helpInfo.GetParameter(parameter)) { @@ -491,7 +486,7 @@ private void ValidateAndThrowIfError(HelpCategory cat) if ((cat & supportedCategories) == 0) { - if (_parameters != null) + if (Parameter != null) { throw PSTraceSource.NewArgumentException("Parameter", HelpErrors.ParamNotSupported, "-Parameter"); @@ -552,7 +547,7 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) // show inline help if (showFullHelp) { - if (_parameters != null) + if (Parameter != null) { GetAndWriteParameterInfo(helpInfo); } @@ -565,11 +560,11 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) } else { - if (_parameters != null) + if (Parameter != null) { - List pInfosList = new List(_parameters.Length); + List pInfosList = new List(Parameter.Length); - foreach (var parameter in _parameters) + foreach (var parameter in Parameter) { foreach (var pInfo in helpInfo.GetParameter(parameter)) { From 61d78cdf4a00efd1b03f5694fa449106792daec0 Mon Sep 17 00:00:00 2001 From: sethvs Date: Wed, 9 Jan 2019 08:21:44 +0300 Subject: [PATCH 04/10] Refactor duplicate pieces of code into a method. --- .../help/HelpCommands.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 3cb2a2e6c94..21a50578e41 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -431,13 +431,10 @@ private PSObject TransformView(PSObject originalHelpObject) /// /// Gets the parameter info for patterns identified 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. /// /// HelpInfo Object to look for the parameter. - private void GetAndWriteParameterInfo(HelpInfo helpInfo) + private PSObject[] GetParameterInfo(HelpInfo helpInfo) { - s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name); List pInfosList = new List(Parameter.Length); foreach (var parameter in Parameter) @@ -448,7 +445,20 @@ private void GetAndWriteParameterInfo(HelpInfo helpInfo) } } - PSObject[] pInfos = pInfosList.ToArray(); + return pInfosList.ToArray(); + } + + /// + /// Gets the parameter info for patterns identified 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. + /// + /// HelpInfo Object to look for the parameter. + private void GetAndWriteParameterInfo(HelpInfo helpInfo) + { + s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name); + + PSObject[] pInfos = GetParameterInfo(helpInfo); if ((pInfos == null) || (pInfos.Length == 0)) { @@ -562,17 +572,7 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) { if (Parameter != null) { - List pInfosList = new List(Parameter.Length); - - foreach (var parameter in Parameter) - { - foreach (var pInfo in helpInfo.GetParameter(parameter)) - { - pInfosList.Add(pInfo); - } - } - - PSObject[] pInfos = pInfosList.ToArray(); + PSObject[] pInfos = GetParameterInfo(helpInfo); if ((pInfos == null) || (pInfos.Length == 0)) { From e15f6eae52bd17e81a529638781d4758b1964eb8 Mon Sep 17 00:00:00 2001 From: sethvs Date: Wed, 9 Jan 2019 08:49:15 +0300 Subject: [PATCH 05/10] Fix CodeFactor issues. --- .../help/HelpCommands.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index 21a50578e41..d4992e95a55 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -430,26 +430,27 @@ private PSObject TransformView(PSObject originalHelpObject) } /// - /// Gets the parameter info for patterns identified Parameter property. + /// Gets the parameter info for patterns identified by Parameter property. /// /// HelpInfo Object to look for the parameter. + /// Array of parameter infos. private PSObject[] GetParameterInfo(HelpInfo helpInfo) { - List pInfosList = new List(Parameter.Length); + List parameterInfosList = new List(Parameter.Length); foreach (var parameter in Parameter) { - foreach (var pInfo in helpInfo.GetParameter(parameter)) + foreach (var parameterInfo in helpInfo.GetParameter(parameter)) { - pInfosList.Add(pInfo); + parameterInfosList.Add(parameterInfo); } } - return pInfosList.ToArray(); + return parameterInfosList.ToArray(); } /// - /// Gets the parameter info for patterns identified Parameter property. + /// 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. /// From 2da2ab3db5ec2d19b86b1309842e1760b2203c96 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 10 Jan 2019 12:07:31 +0300 Subject: [PATCH 06/10] Update src/System.Management.Automation/help/HelpCommands.cs Co-Authored-By: sethvs --- src/System.Management.Automation/help/HelpCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs index d4992e95a55..28073b2dc50 100644 --- a/src/System.Management.Automation/help/HelpCommands.cs +++ b/src/System.Management.Automation/help/HelpCommands.cs @@ -432,7 +432,7 @@ private PSObject TransformView(PSObject originalHelpObject) /// /// Gets the parameter info for patterns identified by Parameter property. /// - /// HelpInfo Object to look for the parameter. + /// HelpInfo object to look for the parameter. /// Array of parameter infos. private PSObject[] GetParameterInfo(HelpInfo helpInfo) { From 6495627fa3f5b10da60006d88686eb413e02707b Mon Sep 17 00:00:00 2001 From: sethvs Date: Tue, 15 Jan 2019 11:13:24 +0300 Subject: [PATCH 07/10] Add test. --- .../engine/Help/HelpSystem.Tests.ps1 | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 10654c8a625..b3cd6941c0e 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -469,3 +469,26 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin $helpObj.description | Out-String | Should -Match $CmdletName } } + +Describe "Validate that Get-Help accepts arrays as the -Parameter parameter value" { + + BeforeAll { + $currentCulture = (Get-Culture).Name + $coreHelpFilePath = Join-Path $PSHOME -ChildPath $currentCulture -AdditionalChildPath 'System.Management.Automation.dll-Help.xml' + if (-not (Test-Path $coreHelpFilePath)) + { + UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers' + } + } + + AfterAll { + 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' + } +} From ed8d6208c4809081032478ff86fdbe7d68bc9790 Mon Sep 17 00:00:00 2001 From: sethvs Date: Tue, 15 Jan 2019 12:29:34 +0300 Subject: [PATCH 08/10] Add tag. --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 9162eec35e5..2d50c6f047b 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -478,7 +478,7 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin } } -Describe "Validate that Get-Help accepts arrays as the -Parameter parameter value" { +Describe "Validate that Get-Help accepts arrays as the -Parameter parameter value" -Tags @('CI') { BeforeAll { $currentCulture = (Get-Culture).Name From 423e50f578194d2506576f69d99caa142c9daa25 Mon Sep 17 00:00:00 2001 From: sethvs Date: Tue, 15 Jan 2019 13:05:06 +0300 Subject: [PATCH 09/10] Fix test. --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index 2d50c6f047b..f599baeedb1 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -478,19 +478,25 @@ Describe 'help can be found for AllUsers Scope' -Tags @('Feature', 'RequireAdmin } } -Describe "Validate that Get-Help accepts arrays as the -Parameter parameter value" -Tags @('CI') { +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 (-not (Test-Path $coreHelpFilePath)) - { - UpdateHelpFromLocalContentPath -ModuleName 'Microsoft.PowerShell.Core' -Scope 'AllUsers' + if (Test-Path $coreHelpFilePath) { + Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue } } AfterAll { - Remove-Item $coreHelpFilePath -Force -ErrorAction SilentlyContinue + Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse } It "Should return help objects for two parameters" { From 4bafe7fc72c03bd7a8860267717fff2cfd44aff7 Mon Sep 17 00:00:00 2001 From: sethvs Date: Tue, 15 Jan 2019 13:44:15 +0300 Subject: [PATCH 10/10] Testing. --- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index f599baeedb1..54f6b7771ab 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -495,10 +495,6 @@ Describe "Get-Help should accept arrays as the -Parameter parameter value" -Tags } } - AfterAll { - Remove-Item $userHelpRoot -Force -ErrorAction SilentlyContinue -Recurse - } - It "Should return help objects for two parameters" { $help = Get-Help -Name Get-Command -Parameter Verb, Noun $help | Should -HaveCount 2