clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.31k stars 1.04k forks source link

Provide better did-you-mean suggestions for swapped words #5029

Open not-my-profile opened 1 year ago

not-my-profile commented 1 year ago

While using the deno CLI (which uses clap) I experienced the following:

$ deno check --write-lock
error: unexpected argument '--write-lock' found

  tip: a similar argument exists: '--no-lock'

The option I wanted was --lock-write.

Another example would be ripgrep e.g. rg --not-type currently suggests --no-pre when it should really be suggesting --type-not.

epage commented 1 year ago

Carrying some of the conversation from the PR

So this will only check for one-"word" swaps and only if the word separator is - (which it really should be) and won't handle typos within those swapped words.

The thing I'm tying to decide if this is too narrow of a niche to include

epage commented 1 year ago

@not-my-profile

Right ... if you want to I can convert the PR to a draft and we can discuss this in an issue.

Personally I think mixing up the order of words of CLI arguments happens much more often for me than misspelling them. E.g. ripgrep has --type-not ... trying --not-type instead is a very easy mistake to make but clap currently suggests --no-pre. I think a small quality of life improvement like this across all clap CLIs would be nice ... sure this logic could be made more elaborate to also handle swaps in arguments consisting of e.g. 3 words but I think 2 word flags are much more common.

epage commented 1 year ago

I want to sit on this to give this more thought. I'm trying to weigh out the couple of specific cases this helps with vs where the line is for us supporting these one-off heuristics.