git-gud
git-gud copied to clipboard
Use fuzzing matching to find commands, provide git-like output
The git command finder has output like
$ git comit
git: 'comit' is not a git command. See 'git --help'.
The most similar command is
commit
We should have something similar
Looking at it, git's built-in command finder doesn't seem like it would work for subcommands.
Running git bbisect
produces the output:
git: 'bbisect' is not a git command. See 'git --help'.
The most similar command is
bisect
But running git bisect hhelp
produces:
usage: git bisect [help|start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run]
instead of suggesting that help
is the most similar command.
I'm looking at the git source code for the command for the help functionality, and it looks like they're using Levenshtein distance to figure out what the most similar commands are. We could probably implement a simple recursive Levenshtein distance calculator and put it into util.py
.
I'm in favor of doing our own Levenshtein fuzzy matching, but I want to check a few things:
- We do not implement it ourselves
- Importing the module doesn't affect our runtime
- The library we use is relatively popular and supports the versions of python we support
If we can't find something that meets those criteria, just check with me and we can decide on what to do
Otherwise, output should still look like this:
git gud: 'bbisect' is not a git gud command. See 'git gud --help'.
The most similar command is
bisect
@sahansk2 Should I assign this to you?
Sorry for not responding to your message then. I don't know if I'll take this, but I was looking through the Python standard library and noticed a function that serves exactly the purpose we want:
https://docs.python.org/3.6/library/difflib.html#difflib.get_close_matches
Passing n=1
as the parameter would basically give us what we need - the issue then is presentation.
I guess we're halfway done. I think this would be a good issue for a newbie