国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

nodejs命令行參數(shù)處理模塊commander使用實(shí)例

2019-11-20 14:08:15
字體:
供稿:網(wǎng)友

誠然,之前處理都是使用內(nèi)置的process.agrv ,這個(gè)能work,但是不好使,于是tj大神給寫了一個(gè),my god,完全的高大上:

1、安裝

復(fù)制代碼 代碼如下:

npm install commander

2、option 解析

Options with commander are defined with the .option() method, also serving as documentation for the options. The example below parses args and options from process.argv, leaving remaining args as the program.args array which were not consumed by options.

復(fù)制代碼 代碼如下:

#!/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', '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.bbq) console.log('  - bbq');
console.log('  - %s cheese', program.cheese);

Short flags may be passed as a single arg, for example -abc is equivalent to -a -b -c. Multi-word options such as “

主站蜘蛛池模板: 白玉县| 长宁县| 大余县| 崇左市| 汤阴县| 天气| 礼泉县| 阳谷县| 金阳县| 凌云县| 曲水县| 清镇市| 施秉县| 泗水县| 永春县| 和龙市| 农安县| 政和县| 肃宁县| 清镇市| 鸡东县| 于田县| 兖州市| 南投市| 渑池县| 辉南县| 简阳市| 阿拉善右旗| 娄底市| 瓦房店市| 台前县| 咸阳市| 临城县| 海兴县| 河北区| 荃湾区| 台北县| 九龙坡区| 高青县| 德惠市| 濮阳市|