Commander.js是Node.js命令行接口的补全解决方案,灵感来源于Ruby的commander。
安装:
$ npm install commander代码示例:
#!/usr/bin/env node /** * Module dependencies. */ var program = require('commander'); program .version('0.0.1') .option('-p, --peppers', 'Add peppers') .option('-P, --pineapple', 'Add pineapple') .option('-b, --bbq-sauce', 'Add bbq sauce') .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble') .parse(process.argv); console.log('you ordered a pizza with:');if (program.peppers) console.log(' - peppers');if (program.pineapple) console.log(' - pineapple');if (program.bbqSauce) console.log(' - bbq');console.log(' - %s cheese', program.cheese);
评论