Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve did-you-mean suggestions by detecting swapped words #4997

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

not-my-profile
Copy link
Contributor

@not-my-profile not-my-profile commented Jul 6, 2023

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.

Resolves #5029.

Comment on lines +38 to +45
let input_words = input.split_once('-');
let candidate_words = candidate.split_once('-');
match (input_words, candidate_words) {
(Some((input1, input2)), Some((candidate1, candidate2))) => {
input1 == candidate2 && input2 == candidate1
}
_ => false,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
(and this is the type of discussion I prefer having in Issues before PRs are created)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

At this point, I would really like to move this discussion to an issue so we decouple the conversation on whether to do it and what we should support from this specific PR (as they can come and go).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #5029 :)

Comment on lines +40 to +41
match (input_words, candidate_words) {
(Some((input1, input2)), Some((candidate1, candidate2))) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this just if a if let?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can be ... I guess I personally prefer a match block but I can change it if you prefer if let.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide better did-you-mean suggestions for swapped words
2 participants