templating icon indicating copy to clipboard operation
templating copied to clipboard

Offer suggestions for typos in template names

Open baronfel opened this issue 3 years ago • 2 comments
trafficstars

Currently System.CommandLine has a feature for typo-correction of commands that looks like this:

➜ dotnet run chioce
'chioce' was not matched. Did you mean one of the following?
choice

This is powered by Levenshtein distance comparisons of command aliases. We should do the same for typos in template short names. Currently we show the following:

➜ dotnet new wbe
No templates found matching: 'wbe'.

We should suggest templates that are withing a given edit-distance from the user input. For example, with wbe as above in a default .NET 7 install:

➜ dotnet new wbe
No templates found matching: 'wbe'.  Did you mean one of the following?
     web
     webconfig

We can use the algorithm from System.CommandLine to power this (at least until I can convince them to make it public). I'd suggest the edit distance used to be 5.

Later efforts could expand this to template argument suggestions.

A different approach might be to change S.CL to offer typo suggestions for arguments and option names as well (instead of commands only), but that would require us to set the valid choices of the template name argument using FromAmong(string[] variants), and that would likely also need configuration about how many suggestions to show (because the template list can be quite long).

baronfel avatar Jul 19 '22 14:07 baronfel

+1 this would be very useful.

sayedihashimi avatar Jul 19 '22 15:07 sayedihashimi

We should also add similar logic on subcommands typos:

>dotnet new uninstal
'uninstal' was not matched. Did you mean one of the following?
uninstall

The message can be:

➜ dotnet new wbe
No templates or subcommands found matching: 'wbe'.  Did you mean one of the following?
     web
     webconfig

vlada-shubina avatar Jul 26 '22 08:07 vlada-shubina