Skip to content
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

Fix Get-Help PSTypeName issue with -Parameter when only one parameter is declared #8754

Merged
merged 1 commit into from Jan 30, 2019

Conversation

pougetat
Copy link

@pougetat pougetat commented Jan 26, 2019

PR Summary

Fix #8697 'Get-Help -Parameter does not correctly set PSTypeName when one parameter is declared'.

PR Context

This issue occurs for the following reason :

  • For a single parameter the FullHelp object contains a PSObject representing the parameter
  • For multiple parameters the FullHelp object conrains a PSObject[] with each element representing a parameter.
    My fix is to manipulate a PSObject[] instead of a PSObject even in the event that it only contains one parameter.

PR Checklist

PSObject[] prmtArray = (PSObject[])LanguagePrimitives.ConvertTo(
prmts.Properties["parameter"].Value,
paramAsPSObjArray != null ? paramAsPSObjArray : param,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could probably condense much of this into the ternary statement, if I'm reading this right...

Suggested change
paramAsPSObjArray != null ? paramAsPSObjArray : param,
paramPSObjArray == null ? paramPSObjArray : new[] { (PSObject)prmts.Properties["parameter"].Value },

Copy link
Author

Choose a reason for hiding this comment

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

The problem is that param is not necessarily PSObject or PSObject[]. It can also be object which makes the cast failure prone.

Copy link
Collaborator

@vexx32 vexx32 Jan 27, 2019

Choose a reason for hiding this comment

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

You can do PSObject.AsPSObject(obj) to safely convert object -> PSObject, but I'm not sure whether that would completely resolve the issue.

That method will also no-op if the input object is already a PSObject.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think it resolves the issue since that method will attempt to create a PSObject from object. What I'm doing here is essentially trying to use the object as is in the form of a PSObject and if it doesn't work then I will just pass the object along to ConvertTo as was done previously. ConvertTo itself knows what to do with a plain object in regards to transforming it into a PSObject.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not 100% sure, but I think that's more or less just what ConvertTo would do itself... I'd have to chase down the convoluted code paths in there, though. I'm sure it's OK to use ConvertTo, though. 🙂

@pougetat pougetat force-pushed the fix-gethelp branch 4 times, most recently from 40bca28 to 0c67a87 Compare January 27, 2019 10:49
test/powershell/engine/Help/HelpSystem.Tests.ps1 Outdated Show resolved Hide resolved
test/powershell/engine/Help/HelpSystem.Tests.ps1 Outdated Show resolved Hide resolved
test/powershell/engine/Help/HelpSystem.Tests.ps1 Outdated Show resolved Hide resolved
test/powershell/engine/Help/HelpSystem.Tests.ps1 Outdated Show resolved Hide resolved
@adityapatwardhan adityapatwardhan self-assigned this Jan 28, 2019
@adityapatwardhan adityapatwardhan changed the title Fix Get-Help issue wih -Parameter option #8697 Fix Get-Help PSTypeName issue with -Parameter when only one parameter is declared Jan 30, 2019
@adityapatwardhan adityapatwardhan merged commit 1d7651f into PowerShell:master Jan 30, 2019
@adityapatwardhan
Copy link
Member

@pougetat Thank you for your contribution!

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 30, 2019
@pougetat pougetat deleted the fix-gethelp branch April 8, 2019 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get-Help -Parameter does not correctly set PSTypeName when one parameter is declared
5 participants