mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Move CommandNotFoundException suggestion to an experimental feature (#8805)
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user