Open danmoseley opened 2 years ago
If this sounds like a good idea to the maintainers, perhaps it's a candidate for 'up for grabs'?
We can get this for free from the typo correction middleware in System.CommandLine, which we should do after looking at the impact to the help messages.
There was also a tab-completion mechanism built for shells: https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/documentation/general/tab-completion.md. Perhaps, both features can complement each other via a common (fuzzy) lookup?
The tab completion support linked in that document is also powered by system.commandline - so the shared data aspect should already be accounted for. In the future we'd like to make tab completion easier to opt into, so that the user doesn't have to modify their shell profiles at all.
For anyone interested:
This won't work out of the box due to the way the .NET CLI hooks up global and local tool lookups - we'd have to do something custom after the second-phase lookup (after global tools).
My preferred way forward would be to integrate global and local tools into the overall command tree so that System.CommandLine's default handling can just take over and provide suggestions.
If I make a typo in my dotnet command, it tells me this:
But dotnet knows that there is a very similar valid option, "build-server".
git, however, is more useful:
Benchmark.NET does this also, eg
They both do this by the well established procedure of selecting the alternatives that have the lowest Levenshtein distance from the invalid input. This can be done whenever the valid inputs are known strings. The typo does not need to be a missing or extra character, it can be a transposition or substitution - Levenshtein distance just ranks by the smallest number of insertions, deletions, or edits between the valid and the invalid strings. Typically, this handles everyday typos effectively.
Benchmark.NET has the MIT license and with attribution dotnet can reuse its code from here When a command or parameter or any other input is not one of a valid list, the CLI simply feeds it, and the valid options, to this Levenshtein calculator and it will return the most likely intended possibilities to display to the user.