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

Hinting command when user types an invalid command #151

Open
minhchu opened this issue May 30, 2016 · 2 comments
Open

Hinting command when user types an invalid command #151

minhchu opened this issue May 30, 2016 · 2 comments

Comments

@minhchu
Copy link

minhchu commented May 30, 2016

Maybe we can add an additional implementation to display similiar command when user types an invalid command
Example:

vorpal
    .command('foo', 'Outputs "foo".')
    .action(function(args, callback()) {
        this.log('foo');
        callback();
    });

vorpal
    .catch('[words...]', 'Catches incorrect commands')
    .action(function (args, callback()) {                
        this.log(args.words.join(' ') + ' is not a valid command.');
        // new function
        // something like vorpal.similiar(args.words[0])
        // to display similiar commands
        callback();
    });

When user type node command.js foozz, it will output:

foozz is not a valid command. Maybe you mean:
    foo
@dthree
Copy link
Owner

dthree commented May 30, 2016

Good idea. I would probably want to t urn this on by default, and only if there isn't a vorpal.catch command declared. Then it could be turned off like:

const vorpal = require('vorpal');

vorpal.delimiter('foo').hints(false).show();

What do you think?


You could probably do a PR on this pretty easily, just use the leven module for Levenshtein distance by @sindresorhus , which you could pick the top score under a certain threshhold of edit distance. This isn't computationally expensive and is a small add.


Should probably go in here:

https://github.com/dthree/vorpal/blob/master/lib/vorpal.js#L1027

@minhchu
Copy link
Author

minhchu commented May 30, 2016

Thanks for your advice. I'll try to do a PR.

minhchu added a commit to minhchu/vorpal that referenced this issue May 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants