Yargs 不验证所需参数

Joa*_*tor 5 node.js

我正在尝试使用 yargs 验证一些参数,如下所示:

\n\n
var args = require('yargs')\n        .command('comando',\n            'comprimenta o usu\xc3\xa1rio', \n            function (yargs){\n                yargs.options({\n                    comando: {\n                        demand: true\n                    }\n                });\n        })\n        .argv;\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我像这样运行我的程序:

\n\n
node app2.js\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者像这样:

\n\n
node app2.js -comando\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我没有从程序中收到任何错误消息。我究竟做错了什么?

\n

bol*_*lav 4

如果您只想提出--comando所需的参数,请尝试以下操作:

\n\n
var args = require('yargs')\n        .command('comando', 'comprimenta o usu\xc3\xa1rio')\n        .demand('comando')\n        .argv;\n
Run Code Online (Sandbox Code Playgroud)\n