dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.63k stars 278 forks source link

Validate not working as expected on piped functions #290

Open oshnix opened 6 years ago

oshnix commented 6 years ago

When you use some commands chained with pipe second command's validate function is triggered by it doesn't reject execution. Here's example:

lorem 5 -u paragraphs | note insert or update
Error with code 23502 happened
    Message: null value in column "scientist_id" violates not-null constraint
    Details: Failing row contains (null, null, ...).

This script should generate lorem ipsum text and then insert or update row in database.
But command note insert or update require two options (ids) and their validation really work:

$ note insert or update 
    scientist id should present and be number
$ note insert or update -s 1
    object id should present and be number

But it behave differently when input is piped from another command. This is how my validation function looks:

function validateNoteParams(args){
    if(typeof args.options.scientist != 'number'){
        return '\tscientist id should present and be number';
    }
    if(typeof args.options.object != 'number'){
        return '\tobject id should present and be number';
    }
    return true;
}