我有一个看起来像这样的vorpal命令: 我正在运行1.9.5版本。
const vorpal = require('vorpal')()
vorpal
.command('temp [dev]')
.validate(function() {
return false
})
.action(function() {
...
})
vorpal.parse(process.argv)
当我在终端中运行pnt temp
时,我会抛出此错误:
/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:169
throw new Error(err);
^
Error: null
at EventEmitter.<anonymous> (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:169:17)
at callback (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:830:22)
at /Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:961:7
at EventEmitter._commandSetCallback (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:446:5)
at EventEmitter.session.completeCommand (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:526:12)
at onCompletion (/Users/samm/Sites/pnt/node_modules/vorpal/dist/session.js:456:10)
at EventEmitter.session.execCommandSet (/Users/samm/Sites/p nt/node_modules/vorpal/dist/session.js:471:5)
at EventEmitter.vorpal._exec (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:960:18)
at EventEmitter.vorpal._execQueueItem (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:751:17)
at EventEmitter.vorpal._queueHandler (/Users/samm/Sites/pnt/node_modules/vorpal/dist/vorpal.js:735:10)
答案 0 :(得分:0)
我承认这看起来很丑陋,他们可能会在未来的版本中解决这个问题,但这看起来是正确的行为。
从false
返回.validate
或字符串会引发错误,因为这意味着您不接受这些参数。如果您返回一个字符串,该字符串将显示给用户(return "I don't want no scrubs."
)。
因此,从您发布的代码中,这是正确的行为。
如果您希望.validate
的错误消息有所不同,我建议您在vorpal的问题跟踪器上发布问题。 (尽管我可以看到你已经这样做了。)