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

Command Suggestion for Incorrect Subcommands #12

Merged

Conversation

vinamra28
Copy link
Contributor

@vinamra28 vinamra28 commented Apr 16, 2021

Earlier there were no suggestions for shp subcommands but with this patch entering wrong subcommands will give suggestions.
example:-

$ shp build cr

Error: unknown command "cr" for "shp build"

Did you mean this?
	create

Also updated the .gitignore file to ignore the binary generated after running go build ./cmd/shp and also ignoring .vscode dir

Signed-off-by: vinamra28 vinjain@redhat.com

@vinamra28
Copy link
Contributor Author

/cc @adambkaplan @alicerum

.gitignore Outdated Show resolved Hide resolved
@vinamra28 vinamra28 force-pushed the subcommand-suggest branch from 60f4f39 to 011a301 Compare April 19, 2021 15:12
pkg/shp/cmd/root.go Outdated Show resolved Hide resolved
pkg/shp/cmd/root_test.go Outdated Show resolved Hide resolved
pkg/shp/suggestion/suggest.go Outdated Show resolved Hide resolved
pkg/shp/suggestion/suggest.go Outdated Show resolved Hide resolved
@vinamra28 vinamra28 force-pushed the subcommand-suggest branch 2 times, most recently from 32ca892 to 39935c2 Compare April 20, 2021 04:29
@vinamra28
Copy link
Contributor Author

vinamra28 commented Apr 23, 2021

@alicerum can you please review?

@alicerum
Copy link
Member

@vinamra28 after discussion with colleagues, I want to ask you to use levenshtein distance function provided by some package.
Library mentioned by @adambkaplan seems to be quite mature and well supported (seeing how issues are being fixed after years of existence), https://pkg.go.dev/github.com/texttheater/golang-levenshtein/levenshtein#DistanceForStrings

Another option would be put this function into some package like util/math of tekton cli and depend on that, or, even better, create a common utility module and make both project depend on it.

Reasoning is that we don't really want to introduce exact same mathematical problems solving algorithms into multiple project. In case there's a problem with it later, we will have to find and fix all the occurrences of such algorithm, and it's just overall not the best approach.

@vinamra28 vinamra28 force-pushed the subcommand-suggest branch from 39935c2 to ca2efe9 Compare April 28, 2021 18:16
@vinamra28
Copy link
Contributor Author

@adambkaplan @alicerum updated the PR based on the comments. Used the library https://github.com/texttheater/golang-levenshtein. Can you please review? 🙂

Copy link
Member

@otaviof otaviof left a comment

Choose a reason for hiding this comment

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

Thanks! It looks good. 👍🏼

pkg/shp/suggestion/suggest.go Outdated Show resolved Hide resolved

// suggestsByPrefixOrLd suggests a command by levenshtein distance or by prefix.
// It returns an empty string if nothing was found
func suggestsByPrefixOrLd(typedName, candidate string, minDistance int) string {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! 👍🏼

@otaviof
Copy link
Member

otaviof commented May 7, 2021

/assign @alicerum

@alicerum
Copy link
Member

alicerum commented May 7, 2021

/approve

Looks good to me, thank you very much @vinamra28

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alicerum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2021
@vinamra28 vinamra28 force-pushed the subcommand-suggest branch from ca2efe9 to 22b4898 Compare May 7, 2021 09:02
vinamra28 added 2 commits May 7, 2021 14:35
Earlier there were no suggestions for shp subcommands but with this patch entering wrong subcommands will give suggestions.
example:- shp build cr

Error: unknown command "cr" for "shp build"

Did you mean this?
	create

Signed-off-by: vinamra28 <vinjain@redhat.com>
Signed-off-by: vinamra28 <vinjain@redhat.com>
@vinamra28 vinamra28 force-pushed the subcommand-suggest branch from 22b4898 to 329128e Compare May 7, 2021 09:06
@alicerum
Copy link
Member

alicerum commented May 7, 2021

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 7, 2021
@openshift-merge-robot openshift-merge-robot merged commit 83fcf89 into shipwright-io:main May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants