我正在尝试使用 yarg 添加命令,但是当我运行代码时,我的命令未添加。
这是我正在尝试的:
const yargs = require('yargs')
//create add command
yargs.command({
command: 'add',
describe: 'to add note',
handler: function() {
console.log('note has been added')
}
})
运行命令:
PS C:\Users\HP\Desktop\node\notes-app> node app.js --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
未添加任何添加命令。
此外,当我尝试通过将 add 作为参数(即 node app.js add)来运行代码时,什么也没有显示。
我现在应该做什么?
最佳答案
yargs.command({
command: 'add',
describe: 'to add note',
handler: function() {
console.log('note has been added')
}
}).parse()
如果你不添加parse(),yargs将不会执行。如果你有太多 yargs 命令类型
yargs.parse()
或
console.log(yargs.argv)
在下面。
关于javascript - 命令未使用 yarg npm 包添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55321403/