安装
npm i commander
示例
// index.js const { Command } = require('commander'); const program = new Command(); // 必填选项 program.requiredOption('-i, --input <filename>', 'input filename'); program.requiredOption('-o, --output <filename>', 'output filename'); program.parse(); console.log(program.opts());
测试
$ node index.js -i name.js -o demo.js { input: 'name.js', output: 'demo.js' }