-
-
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
Have in-house support in-order to recommend matching commands #1015
Comments
Only for me, I think it's not necessary. People can realize it by program.command("*").action(cmd => {
suggestCommand(cmd);
}); And we can find a npm package named I'm not familiar with yargs, it seems that it doesn't have an api to match regex cmd like '*' so it has |
I do not think it likely I would accept a PR for this currently, as we still have some improvements to make in whether Commander warns about unrecognised commands in the first place. (So not "in-house support".) I am interested in how a user might add possible matches, and currently that would be in their own code or in an add-on package. Also interested in how popular an idea this is, so feel free to leave this issue open even if you decide not to investigate yourself. My limited knowledge (not researched) is most computer programs use the Levenshtein distance algorithm. I was casually looking at didyoumean and didyoumean2 in weekend. (Using these as examples rather than recommendations.) (Both roll-your-own solutions and didyoumean also suggested by @oGsLP, thanks for comment ) |
I came across an implementation in comments: #432 (comment) |
@shadowspawn what about documenting how to achieve it with didyoumean. |
Same feedback as building it in, I do not think it likely I would accept a PR for this currently. If the code is not huge, you could simply add it as a comment here though. |
A typical implementaion would be:- const didYouMean = require('didyoumean');
const suggestCommands = cmd => {
const availableCommands = program.commands.map(c => c._name);
const suggestion = didYouMean(cmd, availableCommands);
if (suggestion) {
console.log(`Did you mean ${suggestion}?`));
}
};
program.arguments('<command>').action(cmd => {
program.outputHelp();
console.log(`Unknown command ${cmd}.`));
console.log();
suggestCommands(cmd);
}); |
I have opened a PR to use didYouMean in the README as the example for an unrecognised command #1176 |
#1181 does makes sense in this regard. |
This comment has been minimized.
This comment has been minimized.
Ig it would make much sense for a dedicated section to be introduced within |
I do not wish to put a dedicated section in the README for this. I have considered adding a separate page and examples for such code, and possibly links to modules which implement add-ons to Commander and the like. There has not been compelling enough information so far, but this is one such example. |
Sounds good 👍 |
But the present state with #1176 is essentially causing trouble. |
This issue didn't get any upvotes in six months. I am happy to leave it up to authors for now to roll their own suggestions. Feel free to open a new issue if it comes up again, with new information and renewed interest. Thank you for your contributions. |
yargs comes shipped with a
recommendCommands()
method as part of the public API. It would be great if commander.js would have it as well 👏sample creat
The text was updated successfully, but these errors were encountered: