-
Notifications
You must be signed in to change notification settings - Fork 234
Change Get-Help behavior to return local help when no online help available #721
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
Changes from 6 commits
c35d13e
75f8afb
55936d1
6ad4e91
51a2ae8
0f65dc6
74f04ff
c772aa0
4090e8e
c481d02
d125d66
f100131
c2ba5ad
504a5a8
004d53d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,15 +235,25 @@ protected async Task HandleShowOnlineHelpRequest( | |
string helpParams, | ||
RequestContext<object> requestContext) | ||
{ | ||
if (helpParams == null) { helpParams = "get-help"; } | ||
|
||
var psCommand = new PSCommand(); | ||
psCommand.AddCommand("Get-Help"); | ||
psCommand.AddArgument(helpParams); | ||
psCommand.AddParameter("Online"); | ||
|
||
await editorSession.PowerShellContext.ExecuteCommand<object>(psCommand); | ||
|
||
if (helpParams == null) { helpParams = "Get-Help"; } | ||
string script = @" | ||
[CmdletBinding()] | ||
param ( | ||
[String]$CommandName | ||
) | ||
Try { | ||
Microsoft.PowerShell.Core\Get-Command $CommandName -ErrorAction Stop | Out-Null | ||
} catch [System.Management.Automation.CommandNotFoundException] { | ||
$PSCmdlet.ThrowTerminatingError($PSItem) | ||
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. I think, based on your logic here, that this this @SeeminglyScience correct me if I'm wrong here. 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. in other words you might be able to ditch the try/catch all together. 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. I like it with the try catch because without it looks like this: But I will go with whichever you and @SeeminglyScience want. 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. @tylerl0706 the benefit of using Here's a little function you can use to check it out function Test-TerminatingError {
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory)]
[ValidateSet('NormalThrow', 'ThrowTerminatingError')]
[string] $ThrowType
)
end {
if ($ThrowType -eq 'NormalThrow') { j
Get-Command DefinitelyDoesntExist -ErrorAction Stop
}
try {
Get-Command DefinitelyDoesntExist -ErrorAction Stop
} catch {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
}
} If
It shows the line in the function/script itself that failed, which is implementation detail the user doesn't care about. Contrast that to this:
It also lets you fully (well mostly) customize the displayed error by creating your own All that said, @corbob that is definitely not how I expected that to look... something in our host does not handle that right... We should still stick with it, but we should definitely look into why that's doing that. 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. @SeeminglyScience should we be opening an issue for "something in our host does not handle that right... |
||
} | ||
try { | ||
Microsoft.PowerShell.Core\Get-Help $CommandName -Online | Out-Null | ||
} catch [System.Management.Automation.PSInvalidOperationException] { | ||
Microsoft.PowerShell.Core\Get-Help $CommandName -Full | ||
}"; | ||
PSCommand checkHelpScript = new PSCommand(); | ||
checkHelpScript.AddScript(script,true).AddArgument(helpParams); | ||
await editorSession.PowerShellContext.ExecuteCommand<PSObject>(checkHelpScript, true); | ||
await requestContext.SendResult(null); | ||
} | ||
|
||
|
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.
You should pull this script out to a static private property so it's not created every time the function is run.
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've moved this to a static private property, not sure if positioning it at the top of the file is the best spot for it, or what the convention is for this type of scenario.