假设我有一个文件" test.js":
var args = require('yargs')
.command('command', 'command usage here', {alias: "c"} )
.argv;
然后我跑:
>node test command
我收到了这个错误:
选项的第二个参数必须是对象
如果删除.command的第3个参数:
var args = require('yargs')
.command('command', 'command usage here')
.argv;
一切都很好。
我必须犯一个愚蠢的错误。但我无法弄明白。
由于
答案 0 :(得分:0)
你的第三个参数不是必需的,这就是你删除它时的原因。我很确定第三个参数必须是一个函数调用。
var args = require('yargs')
.command('command',
'command explanation',
function(yargs){
//insert yargs.options here
yargs.options({
c:{
demand: true,//if you require the command
alias: 'c',// you will enter -c to use it
description: 'explain what it does'
}
});
})
.argv;
使用示例可能是:
C:\ WorkingDirectory>节点app.js命令-c run
您的代码可能包含console.log(args.c);//prints out run