我只是想理解yargs模块中使用的命令函数以及传递给它的对象的属性。关于内部使用的处理程序函数。argv是否表示传入命令函数的对象的builder属性?
yargs.command({ //accepts an object as a parameter
command: 'add', //name of command
describe: 'Add a new note', //description,
builder: {
title: {
describe: 'Note title',
demandOption: true, //Title must be provided if true
type: 'string' // needs to be a strin
},
body: {
describe: 'Note body',
demandOption: true, //Title must be provided if true
type: 'string' // needs to be a strin
}
},
handler: function (argv) {
console.log('Title: ' + argv.title)
console.log('Body: ' + argv.body)
}
});```发布于 2020-08-22 00:04:44
此argv是您在运行*.js文件时传递的内容。
此argv还包含关于此js文件的文件位置的两个附加参数。
在此构建器选项中,您可以修改此参数的属性在传递时应如何传递。
就像你可以修改这个参数是否必要一样,这个参数字符串的类型或者其他类似的东西。
there.you,在处理程序中,有一个函数,如果有任何参数被传递,它就会运行,它可以决定如果这些参数被传递,你的程序将做什么
https://stackoverflow.com/questions/63482273
复制相似问题