下面是如何获取第一个和第二个参数的示例:
var argv=require('yargs').argv
var source=argv._[0]
var dest=argv._[1]
或者更好的方法:
const argv = require("yargs").command(
"$0 <source file> [destination file]",
"the default command",
() => {},
function({ sourcefile, destinationfile }) {
console.log({ sourcefile, destinationfile })
},
).argv
$0
是默认命令。
myapp.js <source file> [destination file]
the default command
Options:
--help Show help [boolean]
--version Show version number [boolean]
Not enough non-option arguments: got 0, need at least 1
了解更多: