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

export suggestSimilar (incl. type definition) #1877

Closed
wants to merge 2 commits into from

Conversation

jpilgrim
Copy link

@jpilgrim jpilgrim commented May 8, 2023

Pull Request

Problem

Similar to internal commander functionality I needed a suggestSimilar function in my client (using commander as a dependency).

Solution

Instead of writing the function twice or using another dependency, I simply exported the suggestSimilar function already included in commander.js. That includes its type definitions.

This is a perfect solution, since I needed exactly the format produced by suggestSimilar -- my client is a CLI after all, which is why I use commander.js in the first place.

Just one note: I also updated readme.md and copied the section into readme_zh-CN.md (in english) to simplify translation.

ChangeLog

  • export suggestSimilar to be used in client code as well

@shadowspawn
Copy link
Collaborator

shadowspawn commented May 9, 2023

I am pleased that you think it is useful, but my initial reaction is that I do not want to expose the routine as it is tailored for internal use and not core to what Commander offers. There are multiple libraries that are focused on suggestions.

I'll leave it for a while and think about it some more.

(For interest, the sort of opposite direction I had considered was whether people would want to supply their own implementation. I decided it was not particularly likely so left out, but will reconsider if requested and upvoted.)

@jpilgrim
Copy link
Author

@shadowspawn I understand your concerns. In order to make the function a little bit more generic (i.e., less "tailored for internal use") I have extracted the core part into a new function computeSimilar. I also added tests. Now, only the more general function computeSimilar is exposed.

Commander does not use any dependencies, which is great. For small command line tools, I also want to keep the number of dependencies small. Suggesting a similar word (e.g., for wrongly written filenames) is a typical CLI feature (in a GUI, this usually does not happen as the file is picked from a list). This is a very typical case for CLIs, and I would hate to add another dependency (or otherwise duplicate the solution already found in commander.

If someone needs a more specific solution, one can always use another packages as well.

@shadowspawn
Copy link
Collaborator

Thanks for the suggestion. This is not something I wish to make public at this time.

I think this is the first time the suggestion code has come up for discussion. If there are future issues and demand this can be revisited.

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.

None yet

2 participants