-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add suggestions support #977
Conversation
f18f0b7
to
58b52b6
Compare
Codecov Report
@@ Coverage Diff @@
## master #977 +/- ##
==========================================
+ Coverage 72.91% 73.06% +0.14%
==========================================
Files 33 34 +1
Lines 2481 2539 +58
==========================================
+ Hits 1809 1855 +46
- Misses 565 573 +8
- Partials 107 111 +4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the code, and love that the suggestions stuff is mostly in it's own file 🙏
There's 2 more things I'd like to see from this PR:
- for the total rest coverage in the PR to be increasing, rather than decreasing.
- for suggestions to be added to the v2 manual. I'll stand up a PR for release v2.1 to support this.
1dbbdc7
to
576e593
Compare
Should this be an out of the box OnUsageError handler ? Just wondering, not proposing. |
Seems a matter of taste to me, so I'm open for a vote :) Code coverage seems broken for now, see #985 (comment) |
576e593
to
da26a81
Compare
The coverage now looks better :) |
Minor request: can you avoid force pushing branches that I've already reviewed? I can code review faster when I can use Github's "commits since last push" feature, and force pushing breaks that. |
Sure, I can do this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 only a few non-blocking suggestions!
// command name | ||
func suggestCommand(commands []*Command, provided string) (suggestion string) { | ||
distance := 0.0 | ||
for _, command := range commands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐ (nice to have) I'm not sure about this suggestion, but: would it be a good idea to consider suggesting sub commands too? I'm imagining an example CLI that has exactly these 3 commands
docker info
docker info containers
docker info images
and I input this
docker containers
I would be expecting to get a suggestion like
did you mean: docker info containers?
whereas I believe this code with give me
did you mean: docker info?
is that a correct assumption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is correct that it would only suggest docker info
in that case, because can only suggest one command with the current implementation. I'm also not sure if we should add such a traversal suggestion to the users. It might be helpful but it also might result in confusing them. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ fair!
ab18abf
to
07b5809
Compare
👀 |
6d71d67
to
177d8d4
Compare
I rebased on top of the latest master. Do you think we can move forward with this, @lynncyrin @AudriusButkevicius @asahasrabuddhe ? |
So my only comment is that "Suggest" is a poor name, we have UseXYZ everywhere, so the property could be more descriptive. |
Hm, how about |
Sounds better. Perhaps others have suggestions. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:seal-of-approval:
pending the tests passing ^^
The new option `app.Suggest` enables command and flag suggestions via the jaro-winkler distance algorithm. Flags are scoped to their appropriate commands whereas command suggestions are scoped to the current command level. Signed-off-by: Sascha Grunert <[email protected]>
1aa9d8a
to
002bde2
Compare
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else. |
Closing this as it has become stale. |
Hey, just curious what ended up happening with this feature. Looks like stale bot closed it but seems like the work was good. Getting suggestions on invalid commands would still be a nice feature to have |
Hey, Why don't you merge this feature? |
Add suggestions support (#977)
Motivation
The new option
app.Suggest
enables command and flag suggestions via the jaro-winkler distance algorithm. Flags are scoped to their appropriate commands whereas command suggestions are scoped to the current command level.Closes #895
Release Notes
Add "Did you mean" suggestion support to flags and commands. This feature can be enabled by setting
app.Suggest = true
.Changes
Testing
Added unit tests :)
Reviewer Guidelines
The scope of the suggestions should be correct, that we do not suggest flags from other sub-commands.