rebar3
rebar3 copied to clipboard
"Did you mean ...?" suggestions for misspelled commands
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.name
s 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.
👍
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
.
I've long though we should have Jaro/Damerau-Levenstein in the string
module in Erlang. So a PR there would be appriciated :)
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.
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.
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 :)
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!
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.