Update 'CommandNotFound' fuzzy suggestion to only return unique results (#8640)

This commit is contained in:
Steve Lee 2019-01-14 14:28:15 -08:00 committed by Dongbo Wang
parent 812456f84c
commit c3cb6df809
2 changed files with 7 additions and 6 deletions

View file

@ -68,7 +68,7 @@ namespace System.Management.Automation
[System.Diagnostics.DebuggerHidden()]
param([string] $formatString)
$formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -ExpandProperty Name))
$formatString -f [string]::Join(', ', (Get-Command $lastError.TargetObject -UseFuzzyMatch | Select-Object -First 10 -Unique -ExpandProperty Name))
";
private static ArrayList s_suggestions = new ArrayList(

View file

@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Get-Command CI tests" -Tag Feature {
Describe "Get-Command Feature tests" -Tag Feature {
Context "-UseFuzzyMatch tests" {
It "Should match cmdlets" {
$cmds = Get-Command get-hlp -UseFuzzyMatch
@ -10,14 +10,15 @@ Describe "Get-Command CI tests" -Tag Feature {
}
It "Should match native commands" {
$ping = "ping"
$input = "pwsg"
$expectedcmd = "pwsh"
if ($IsWindows) {
$ping = "PING.EXE"
$expectedcmd = "pwsh.EXE"
}
$cmds = Get-Command pinh -UseFuzzyMatch
$cmds = Get-Command $input -UseFuzzyMatch
$cmds.Count | Should -BeGreaterThan 0
$cmds.Name | Should -Contain $ping
$cmds.Name | Should -Contain $expectedcmd
}
}