-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Change Get-Help cmdlet -Parameter parameter so it accepts string arrays. #8454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7875ad4
Get-Help cmdlet -Parameter parameter accepts string array.
sethvs c36ba83
Fix variable names.
sethvs 592ab62
Use public string[] Parameter
sethvs 61d78cd
Refactor duplicate pieces of code into a method.
sethvs e15f6ea
Fix CodeFactor issues.
sethvs 2da2ab3
Update src/System.Management.Automation/help/HelpCommands.cs
iSazonov 6495627
Add test.
sethvs 49740db
Merge branch 'master' into helpParameter
sethvs ed8d620
Add tag.
sethvs 423e50f
Fix test.
sethvs 4bafe7f
Testing.
sethvs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -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); | ||
|
|
||
| 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)) | ||
| { | ||
|
|
@@ -479,7 +500,7 @@ private void ValidateAndThrowIfError(HelpCategory cat) | |
|
|
||
| if ((cat & supportedCategories) == 0) | ||
| { | ||
| if (!string.IsNullOrEmpty(Parameter)) | ||
| if (Parameter != null) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please comment why we need the change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
|
@@ -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); | ||
| } | ||
|
|
@@ -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; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 != nullchecks to the method.There was a problem hiding this comment.
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.