git-gud icon indicating copy to clipboard operation
git-gud copied to clipboard

Use fuzzing matching to find commands, provide git-like output

Open benthayer opened this issue 4 years ago • 5 comments

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

benthayer avatar Apr 03 '20 03:04 benthayer

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.

sahansk2 avatar May 20 '20 19:05 sahansk2

I'm in favor of doing our own Levenshtein fuzzy matching, but I want to check a few things:

  1. We do not implement it ourselves
  2. Importing the module doesn't affect our runtime
  3. 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

benthayer avatar May 30 '20 20:05 benthayer

@sahansk2 Should I assign this to you?

benthayer avatar Aug 10 '20 05:08 benthayer

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.

sahansk2 avatar Apr 22 '21 05:04 sahansk2

I guess we're halfway done. I think this would be a good issue for a newbie

benthayer avatar Apr 22 '21 13:04 benthayer