Provide relevant suggestions when dotnet command is not found
See original GitHub issueIf I make a typo in my dotnet command, it tells me this:
C:\git\performance>dotnet buildserver
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-buildserver does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
But dotnet knows that there is a very similar valid option, “build-server”.
git, however, is more useful:
C:\git\performance>git cherrypick abc123
git: 'cherrypick' is not a git command. See 'git --help'.
The most similar command is
cherry-pick
Benchmark.NET does this also, eg
[2022/02/07 18:13:46][INFO] You must have made a typo in '*ByteMark.BenchFurier*'. Suggestions:
[2022/02/07 18:13:46][INFO] ByteMark.BenchFourier
[2022/02/07 18:13:46][INFO] To print all available benchmarks use `--list flat` or `--list tree`.
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.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (6 by maintainers)
Top GitHub Comments
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.
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.