Move CommandNotFoundException suggestion to an experimental feature (#8805)

This commit is contained in:
Steve Lee
2019-02-06 13:59:14 -08:00
committed by Andrew
parent 53ad39772c
commit d9be6483f6
2 changed files with 48 additions and 20 deletions
@@ -111,6 +111,9 @@ namespace System.Management.Automation
new ExperimentalFeature(
name: "PSTempDrive",
description: "Create TEMP: PS Drive mapped to user's temporary directory path"),
new ExperimentalFeature(
name: "PSCommandNotFoundSuggestion",
description: "Recommend potential commands based on fuzzy search on a CommandNotFoundException"),
};
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
@@ -71,27 +71,52 @@ namespace System.Management.Automation
$formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -Unique -ExpandProperty Name))
";
private static ArrayList s_suggestions = new ArrayList(
new Hashtable[] {
NewSuggestion(1, "Transactions", SuggestionMatchType.Command, "^Start-Transaction",
SuggestionStrings.Suggestion_StartTransaction, true),
NewSuggestion(2, "Transactions", SuggestionMatchType.Command, "^Use-Transaction",
SuggestionStrings.Suggestion_UseTransaction, true),
NewSuggestion(3, "General", SuggestionMatchType.Dynamic,
ScriptBlock.CreateDelayParsedScriptBlock(s_checkForCommandInCurrentDirectoryScript, isProductCode: true),
ScriptBlock.CreateDelayParsedScriptBlock(s_createCommandExistsInCurrentDirectoryScript, isProductCode: true),
new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandExistsInCurrentDirectory) },
true),
NewSuggestion(
id: 4,
category: "General",
matchType: SuggestionMatchType.ErrorId,
rule: "CommandNotFoundException",
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_getFuzzyMatchedCommands, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandNotFound) },
enabled: true)
private static ArrayList s_suggestions = InitializeSuggestions();
private static ArrayList InitializeSuggestions()
{
ArrayList suggestions = new ArrayList(
new Hashtable[]
{
NewSuggestion(
id: 1,
category: "Transactions",
matchType: SuggestionMatchType.Command,
rule: "^Start-Transaction",
suggestion: SuggestionStrings.Suggestion_StartTransaction,
enabled: true),
NewSuggestion(
id: 2,
category: "Transactions",
matchType: SuggestionMatchType.Command,
rule: "^Use-Transaction",
suggestion: SuggestionStrings.Suggestion_UseTransaction,
enabled: true),
NewSuggestion(
id: 3,
category: "General",
matchType: SuggestionMatchType.Dynamic,
rule: ScriptBlock.CreateDelayParsedScriptBlock(s_checkForCommandInCurrentDirectoryScript, isProductCode: true),
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_createCommandExistsInCurrentDirectoryScript, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandExistsInCurrentDirectory) },
enabled: true)
});
if (ExperimentalFeature.IsEnabled("PSCommandNotFoundSuggestion"))
{
suggestions.Add(
NewSuggestion(
id: 4,
category: "General",
matchType: SuggestionMatchType.ErrorId,
rule: "CommandNotFoundException",
suggestion: ScriptBlock.CreateDelayParsedScriptBlock(s_getFuzzyMatchedCommands, isProductCode: true),
suggestionArgs: new object[] { CodeGeneration.EscapeSingleQuotedStringContent(SuggestionStrings.Suggestion_CommandNotFound) },
enabled: true));
}
);
return suggestions;
}
#region GetProfileCommands
/// <summary>