我在使用指挥官时遇到问题: https://github.com/tj/commander.js/
program
.command('school')
.arguments("<year>")
.option("--month <month>", "specify month")
.parse(process.argv)
.action(function (year) {
console.log(`the year is ${year} and the month is ${program.month}`);
});
我不知道为什么,但即使我使用 --month 12
运行,program.month
也未定义。
提前致谢。
最佳答案
尝试使用program.commands[0].month
而不是program.month
不过,你应该像这样访问变量,这很奇怪。
也许你可以通过 .action
参数获取month
?我自己对指挥官不太熟悉。
关于node.js - Node 命令选项未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37005123/