Closed scotthovestadt closed 8 years ago
Please merge in https://github.com/dthree/vorpal/pull/51
Thank you!
Any update on this PR? I am a little stuck waiting for this fix :+1: thanks for this awesome project.
Just merged and published. And you're welcome!
AWESOME, thanks!
Hi,
I also have this problem. When i'm passing JSON as argument value it's interpreted like an object... The result is strange.. How can I do to pass JSON ?
code
vorpal
.command('--test-sync <payload>')
.description('Synchronize group.')
.option('--payload <required>', 'Pass JSON payload.')
.validate((args) => {
console.log(args.payload)
try {
JSON.parse(args.payload)
} catch (e) {
return 'You only can pass JSON.'
}
return true
})
.action((args, callback) => {
console.log('test');
callback();
});
Command:
$ node index.js --test-sync --payload '{"hello": "world"}'
Output:
hello
Regards,
@rimiti try:
$ node index.js --test-sync --payload '`{"hello": "world"}`'
It seems that the outer single quotes are being removed before passing for processing by Vorpal which is why Vorpal is thinking hello
and world
are separate values. By wrapping the payload in an extra pair of backticks, you let Vorpal know that the whole string is a single argument which is then correctly processed.
There are a few types of arguments that can't be parsed in the REPL. For example, it's impossible to pass a JSON object.
I would like the argument parser to accommodate the following arguments:
I'm working on code to do this. I don't think it's actually that complicated. Do you agree with the spec?