Move warning message to EndProcessing so it only shows up once (#9385)
This commit is contained in:
parent
600a93750e
commit
5e58e30d20
2 changed files with 18 additions and 2 deletions
|
@ -30,6 +30,14 @@ namespace Microsoft.PowerShell.Commands
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public ConfigScope Scope { get; set; } = ConfigScope.CurrentUser;
|
public ConfigScope Scope { get; set; } = ConfigScope.CurrentUser;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// EndProcessing method.
|
||||||
|
/// </summary>
|
||||||
|
protected override void EndProcessing()
|
||||||
|
{
|
||||||
|
WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -87,8 +95,6 @@ namespace Microsoft.PowerShell.Commands
|
||||||
cmdlet.WriteError(new ErrorRecord(new ItemNotFoundException(errMsg), "ItemNotFoundException", ErrorCategory.ObjectNotFound, name));
|
cmdlet.WriteError(new ErrorRecord(new ItemNotFoundException(errMsg), "ItemNotFoundException", ErrorCategory.ObjectNotFound, name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdlet.WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,4 +94,14 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||||
& $cmdlet ExpTest.FeatureOne -WarningVariable warning -WarningAction SilentlyContinue
|
& $cmdlet ExpTest.FeatureOne -WarningVariable warning -WarningAction SilentlyContinue
|
||||||
$warning | Should -Not -BeNullOrEmpty -Because "A warning message is always given indicating restart is required"
|
$warning | Should -Not -BeNullOrEmpty -Because "A warning message is always given indicating restart is required"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Multiple features enabled will only output one warning message for <cmdlet>" -TestCases @(
|
||||||
|
@{ cmdlet = "Enable-ExperimentalFeature" },
|
||||||
|
@{ cmdlet = "Disable-Experimentalfeature" }
|
||||||
|
) {
|
||||||
|
param ($cmdlet)
|
||||||
|
|
||||||
|
Get-ExperimentalFeature | & $cmdlet -WarningAction SilentlyContinue -WarningVariable warning
|
||||||
|
$warning | Should -HaveCount 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue