GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add support to show suggestions on CommandNotFound exception by SteveL-MSFT · Pull Request #8458 · PowerShell/PowerShell

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Dec 13, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Summary

Add -UseFuzzyMatching switch to Get-Command to return commands that fuzzy match to the name in order of closest match to least. Integrate this with the suggestion framework so that on a CommandNotFound exception, suggestions are shown for likely commands the user intended. The suggestions are part of the console host and write directly to the console so don't see a way to test that. In the future, we should consider changing that to using information stream.

Example usage

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Doc -UseFuzzyMatching switch added to Get-Command MicrosoftDocs/PowerShell-Docs#3429
      • Issue filed - Issue link:
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@SteveL-MSFT Steve Lee (SteveL-MSFT) assigned Travis Plunk (TravisEz13) Dec 13, 2018
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested review from Paul Higinbotham (PaulHigin), Andrew (anmenaga) and Rob Holt (rjmholt) December 13, 2018 19:04
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested review from Bruce Payette (BrucePay) and Dongbo Wang (daxian-dbw) as code owners December 13, 2018 19:04
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the fuzzy-match branch 3 times, most recently from c19e787 to 34e954b Compare December 14, 2018 18:32
@SteveL-MSFT Steve Lee (SteveL-MSFT) mentioned this pull request Dec 14, 2018
Doc -UseFuzzyMatching switch added to Get-Command MicrosoftDocs/PowerShell-Docs#3429
Merged
2 of 9 tasks
@iSazonov

Ilya (iSazonov) commented Dec 14, 2018

Copy link
Copy Markdown
Collaborator

We could consider other names of the parameter: -Fuzzy, -FuzzyMatching, -ShowSuggestions, -Suggestions.

We need PowerShell Committee approvement for the new public API.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Dec 14, 2018
@rjmholt

Rob Holt (rjmholt) commented Dec 17, 2018

Copy link
Copy Markdown
Collaborator

We could introduce a test hook to do something like write output to the information stream or to a variable for testing purposes for now

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) suggested changes Dec 17, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/HostUtilities.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/utils/FuzzyMatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Dec 18, 2018

Copy link
Copy Markdown
Member Author

Rob Holt (@rjmholt) I suggest we defer the test hook as that would make sense for testing suggestions in general and not this specific change.

rjmholt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin
Paul Higinbotham (PaulHigin) approved these changes Dec 18, 2018
View reviewed changes
@iSazonov

Ilya (iSazonov) commented Dec 18, 2018

Copy link
Copy Markdown
Collaborator

It was good to have a tracking issue if we needed these special tests.

rjmholt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Dec 18, 2018

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) created #8486

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rjmholt
Rob Holt (rjmholt) reviewed Dec 18, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/HostUtilities.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/GetCommandCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/Modules/ModuleUtils.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/HostUtilities.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/HostUtilities.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/utils/FuzzyMatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13

Travis Plunk (TravisEz13) commented Jan 3, 2019

Copy link
Copy Markdown
Member

Steve Lee (@SteveL-MSFT) Do you want to wait on Rob to review your changes?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Jan 4, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Travis Plunk (@TravisEz13) if Rob Holt (@rjmholt) has further comments, we can treat it as a separate issue and PR. Would like to get this in for next Preview

rjmholt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jan 4, 2019

Copy link
Copy Markdown
Collaborator

It would be good to fix some style issues and "s_" before merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

SteveL-MSFT
Steve Lee (SteveL-MSFT) commented Jan 5, 2019
View reviewed changes
Comment thread src/System.Management.Automation/engine/Modules/ModuleUtils.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Jan 9, 2019

Copy link
Copy Markdown
Member Author

@PowerShell/powershell-committee reviewed this and is ok with -UseFuzzyMatching

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jan 9, 2019
Steve Lee (SteveL-MSFT) added 4 commits January 9, 2019 16:32
@SteveL-MSFT
[feature]
bea7335
support fuzzy matching with get-command and on CommandNotFound exception, show suggestion
@SteveL-MSFT
fix CodeFactor issues
42e8452
@SteveL-MSFT
change algorithm to use Damerau-Levenshtein Distance which is more us…
bef4bc1
…eful in finding close matches
@SteveL-MSFT
address Paul's feedback
6a21e2a
removed use of Tuple and created struct
Steve Lee (SteveL-MSFT) added 2 commits January 9, 2019 16:33
@SteveL-MSFT
address Rob's feedback
68b6f7e
@SteveL-MSFT
Update src/System.Management.Automation/engine/Modules/ModuleUtils.cs
580911b
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the fuzzy-match branch from 1d51a6d to 580911b Compare January 10, 2019 00:33
rjmholt
Rob Holt (rjmholt) approved these changes Jan 10, 2019
View reviewed changes
@TravisEz13 Travis Plunk (TravisEz13) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jan 10, 2019
@TravisEz13
Travis Plunk (TravisEz13) merged commit b87cd1c into PowerShell:master Jan 10, 2019
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the fuzzy-match branch January 10, 2019 21:41
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@SteveL-MSFT @TravisEz13
Add support to show suggestions on CommandNotFound exception (PowerSh…
540bbec
…ell#8458)

* support fuzzy matching with get-command and on CommandNotFound exception, show suggestion
* fix CodeFactor issues
* change algorithm to use Damerau-Levenshtein Distance which is more useful in finding close matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
+2 more reviewers
@rjmholt Rob Holt (rjmholt) rjmholt approved these changes
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@TravisEz13 Travis Plunk (TravisEz13)

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@SteveL-MSFT @iSazonov @rjmholt @TravisEz13 @PaulHigin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.