rebar3 icon indicating copy to clipboard operation
rebar3 copied to clipboard

"Did you mean ...?" suggestions for misspelled commands

Open the-mikedavis opened this issue 7 months ago • 7 comments

Some CLI tools make suggestions when you mistype a command. For example with Mix or Cargo:

$ mix hel
** (Mix) The task "hel" could not be found. Did you mean "help"?
$ cargo hel
error: no such subcommand: `hel`

	Did you mean `help`?

They find any commands where the edit distance to the input command is above some threshold. Mix uses Jaro distance while Cargo uses Damerau–Levenshtein.

I think it would be an easy QoL win to add this to rebar. Elixir's String.jaro_distance/2 is not a very large chunk of code when translated / vendored: https://gist.github.com/the-mikedavis/db39019721fab873980df3560345a93b. Then any places that return an error message that Command ~ts not found can suggest #provider.names where the jaro distance is close enough to 1.0 (Mix uses 0.8).

What do you think? I could submit a PR if you're interested.

the-mikedavis avatar Nov 08 '23 21:11 the-mikedavis

👍

In erlang_ls' els_utils.erl you'll already find references (in Erlang) to both mentioned distance algo.s: Jaro and Damerau-Levenshtein. Maybe worth a look (?)

Fwiw, I'd very much like to see this in rebar3.

paulo-ferraz-oliveira avatar Nov 08 '23 22:11 paulo-ferraz-oliveira

I've long though we should have Jaro/Damerau-Levenstein in the string module in Erlang. So a PR there would be appriciated :)

garazdawi avatar Nov 09 '23 09:11 garazdawi

Yeah I don't have any opposition to that. The State contains a list of all live providers, and you can see them being searched in rebar_core. Be aware that you can also get commands such as rebar3 namespace cmd and that either the namespace or the command can be misspelled, but even just doing the command would be an improvement.

See https://github.com/erlang/rebar3/blob/a16f41aef7f004394f761f1dae108231ca0ec76e/apps/rebar/src/rebar_core.erl#L97-L107 for the specific bit where it complains of things not being found.

ferd avatar Nov 14 '23 19:11 ferd

I've long though we should have Jaro/Damerau-Levenstein in the string module in Erlang. So a PR there would be appriciated :)

Seems like I triggered one of my collegues at Erlang/OTP team, so we will soon see a PR for this in the Erlang/OTP repo.

garazdawi avatar Nov 14 '23 19:11 garazdawi

Ah, I had actually already started on a PR to Erlang/OTP. I will submit what I have upstream and they can take it over or supersede it if they'd like :)

the-mikedavis avatar Nov 14 '23 21:11 the-mikedavis

Ah, I had actually already started on a PR to Erlang/OTP. I will submit what I have upstream and they can take it over or supersede it if they'd like :)

Thats what you get when you use gossip as coordination protocol :) Always good to have more implementation to take inspiration from!

garazdawi avatar Nov 15 '23 07:11 garazdawi

If we do depend on the Erlang/OTP module, we'll need to do a dynamic check to avoid failing when running on older releases. It's rather straightforward, just something we need to make an exception for.

ferd avatar Nov 15 '23 15:11 ferd