国产探花免费观看_亚洲丰满少妇自慰呻吟_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 “

主站蜘蛛池模板: 宣恩县| 津南区| 碌曲县| 屯昌县| 临夏市| 鄂托克前旗| 正定县| 清镇市| 苍溪县| 皮山县| 西宁市| 桓台县| 兴化市| 永修县| 临潭县| 大石桥市| 天津市| 庆云县| 长海县| 治县。| 岳阳市| 合水县| 萨迦县| 元阳县| 宕昌县| 武山县| 双城市| 扶余县| 安国市| 康乐县| 巫溪县| 荔浦县| 岳阳县| 岱山县| 明光市| 囊谦县| 永嘉县| 南靖县| 颍上县| 四平市| 宁陕县|