码迷,mamicode.com
首页 > Web开发 > 详细

nodejs Commander 命令行神器简单示例

时间:2018-06-16 11:48:19      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:foreach   usr   run   ejs   The   nod   ignore   and   node   

gen.js

#!/usr/bin/env node
var program = require(‘commander‘);

 program
   .version(‘0.0.1‘)
   .option(‘-C, --chdir <path>‘, ‘change the working directory‘)
   .option(‘-c, --config <path>‘, ‘set config path. defaults to ./deploy.conf‘)
   .option(‘-T, --no-tests‘, ‘ignore test hook‘)
   .option(‘-p, --peppers‘, ‘Add peppers‘)
   .option(‘-P, --pineapple‘, ‘Add pineapple‘)
   .option(‘-b, --bbq-sauce‘, ‘Add bbq sauce‘)
   .option(‘--p, --fuck-you‘, ‘fuckyou‘)
   .option(‘build --env <fuckyou>‘, ‘fuckyou2‘)
   .parse(process.argv);

if (program.peppers) console.log(‘  - peppers‘);
if (program.pineapple) console.log(‘  - pineapple‘);
if (program.bbqSauce) console.log(‘  - bbq‘);
if (program.fuckYou) console.log(‘fuckyou‘);
if (program.env && program.args.length != 0) {
    console.log(program.args);
}

 program
   .command(‘init‘)
   .description(‘run remote setup commands‘)
   .action(function() {
     console.log(‘setup‘);
   });

 program
   .command(‘exec <cmd>‘)
   .description(‘run the given remote command‘)
   .action(function(cmd) {
     console.log(‘exec "%s"‘, cmd);
   });

 program
   .command(‘teardown <dir> [otherDirs...]‘)
   .description(‘run teardown commands‘)
   .action(function(dir, otherDirs) {
     console.log(‘dir "%s"‘, dir);
     if (otherDirs) {
       otherDirs.forEach(function (oDir) {
         console.log(‘dir "%s"‘, oDir);
       });
     }
   });

 

nodejs Commander 命令行神器简单示例

标签:foreach   usr   run   ejs   The   nod   ignore   and   node   

原文地址:https://www.cnblogs.com/CyLee/p/9189852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!