Closed scotthovestadt closed 8 years ago
I would just do a manual validation. Something like this:
const valids = ['insert', 'update', 'upsert'];
if (valids.indexOf(args.strategy) === -1) {
this.log('Please enter a valid strategy');
cb();
return
}
This is actually a good question that will probably come up a lot. Would you mind posting this on Stack Overflow? There's a vorpal.js
tag you can use.
I have posted a question on this:
http://stackoverflow.com/questions/33460454/validating-a-command-in-vorpal-js
Thanks.
The problem with this approach is it won't validate the arguments until the command is executed, which is a problem when you are piping commands together. Additionally, if you log an error it'll just go to the piped command.
I think we need to add a "validate" method to each command that can be called to validate arguments when the command is initialized but before it's executed?
Okay I'm totally down with this.
Re-open issue please!
:smiley:
@dthree Can you review https://github.com/dthree/vorpal/pull/57
If I have a command that looks like:
If strategy can only be "insert", "update", or "upsert", for example, how do I use Vorpal to validate it?