8000 Fixing issue with help progress by powercode · Pull Request #8788 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

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
32 changes: 23 additions & 9 deletions src/System.Management.Automation/help/HelpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ protected override void BeginProcessing()
/// </summary>
protected override void ProcessRecord()
{
HelpSystem helpSystem = this.Context.HelpSystem;
try
{
this.Context.HelpSystem.OnProgress += new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);
helpSystem.OnProgress += new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);

bool failed = false;
HelpCategory helpCategory = ToHelpCategory(Category, ref failed);
Expand All @@ -268,7 +269,7 @@ protected override void ProcessRecord()
// the idea is to use yield statement in the help lookup to speed up
// perceived user experience....So HelpSystem.GetHelp returns an
// IEnumerable..
IEnumerable<HelpInfo> helpInfos = this.Context.HelpSystem.GetHelp(helpRequest);
IEnumerable<HelpInfo> helpInfos = helpSystem.GetHelp(helpRequest);
// HelpCommand acts differently when there is just one help object and when
// there are more than one object...so handling this behavior through
// some variables.
Expand Down Expand Up @@ -319,13 +320,13 @@ protected override void ProcessRecord()

// show errors only if there is no wildcard search or VerboseHelpErrors is true.
if (((countOfHelpInfos == 0) && (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)))
|| this.Context.HelpSystem.VerboseHelpErrors)
|| helpSystem.VerboseHelpErrors)
{
// Check if there is any error happened. If yes,
// pipe out errors.
if (this.Context.HelpSystem.LastErrors.Count > 0)
if (helpSystem.LastErrors.Count > 0)
{
foreach (ErrorRecord errorRecord in this.Context.HelpSystem.LastErrors)
foreach (ErrorRecord errorRecord in helpSystem.LastErrors)
{
WriteError(errorRecord);
}
Expand All @@ -334,9 +335,11 @@ protected override void ProcessRecord()
}
finally
{
this.Context.HelpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);
helpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress);
HelpSystem_OnComplete();

// finally clear the ScriptBlockAst -> Token[] cache
this.Context.HelpSystem.ClearScriptBlockTokenCache();
helpSystem.ClearScriptBlockTokenCache();
}
}

Expand Down Expand Up @@ -657,9 +660,20 @@ private void LaunchOnlineHelp(Uri uriToLaunch)

private void HelpSystem_OnProgress(object sender, HelpProgressInfo arg)
{
ProgressRecord record = new ProgressRecord(0, this.CommandInfo.Name, arg.Activity);
var record = new ProgressRecord(0, this.CommandInfo.Name, arg.Activity)
{
PercentComplete = arg.PercentComplete
};

record.PercentComplete = arg.PercentComplete;
WriteProgress(record);
}

private void HelpSystem_OnComplete()
{
var record = new ProgressRecord(0, this.CommandInfo.Name, "Completed")
{
RecordType = ProgressRecordType.Completed
};

WriteProgress(record);
}
Expand Down
17 changes: 15 additions & 2 deletions test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ Describe "Validate that get-help works for CurrentUserScope" -Tags @('CI') {
}
}

Describe "Validate that get-help works for AllUsers Scope" -Tags @('Feature','RequireAdminOnWindows', 'RequireSudoOnUnix') {
Describe "Testing Get-Help Progress" -Tags @('Feature') {
It "Last ProgressRecord should be Completed" {
try {
$j = Start-Job { Get-Help DoesNotExist }
$j | Wait-Job
$j.ChildJobs[0].Progress[-1].RecordType | Should -Be ([System.Management.Automation.ProgressRecordType]::Completed)
}
finally {
$j | Remove-Job
}
}
}

Describe "Validate that get-help works for AllUsers Scope" -Tags @('Feature', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
Expand Down Expand Up @@ -507,7 +520,7 @@ Describe "Help failure cases" -Tags Feature {
It "An error is returned for a topic that doesn't exist: <command>" -TestCases @(
@{ command = "help" },
@{ command = "get-help" }
){
) {
param($command)

{ & $command foobar -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand"
Expand Down
0