zoukankan      html  css  js  c++  java
  • 一、commander

    #!/usr/bin/env node
    const program = require('commander');
    const colors  = require('colors');
    const pkg = require('./package.json');
    function range(val, d) {
        return val.split('..').map(Number);
      }
       
      function list(val) {
        return val.split(',');
      }
       
      function collect(val, memo) {
        memo.push(val);
        return memo;
      }
       
      function increaseVerbosity(v, total) {
        return total + 1;
      }
    program
        .version(pkg.version, '-v, --version')
        .option('-u, --username <firstname>', 'add username')
        .option('-p, --password [num]', 'add password')
        .option('--no-sauce', 'Remove sauce')
    
        // .option('-i, --integer <n>', 'An integer argument', parseInt)
        .option('-f, --float <n>', 'A float argument', parseFloat)
        .option('-r, --range [a..b]', 'A range', range, 12)
        .option('-l, --list <items>', 'A list', list)
        .option('-o, --optional [value]', 'An optional value')
        .option('-c, --collect [value]', 'A repeatable value', collect, [])
        .option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
     
    
    
    program
        .command('create <project> [rest...]')
        .alias('init')
        .description('ssy cli description')
        .option('-i, --information [info]', 'add information')
        .action((projectName, cmd, options)=>{
            console.log("ssy",projectName, cmd, options.information)
        })
    
    if (!process.argv.slice(2).length) {
        program.outputHelp(make_red);
    }
           
    function make_red(txt) {
        return colors.red(txt); //display the help text in red on the console
    }
    // must be before .parse() since
    // node's emit() is immediate
    program.on('--help', function(){
        console.log('')
        console.log('Examples:');
        console.log('  $ ssy --help');
        console.log('  $ ssy -h');
    });
    program.parse(process.argv);
    // console.log(program);
  • 相关阅读:
    QtAV编译
    git 恢复到刚刚clone下来的状态
    select2 清除选中项解决办法
    mysql: 查看某库表大小
    C# Linq 交集、并集、差集、去重
    mvc ajax访问后台时session过期无法跳转到Login页面问题解决
    Asp.net:上传文件超过了最大请求长度
    Firebug 没死,活在 Firefox DevTools 中
    vs2015 加载项目的时启动:无法启动 IIS Express Web 服务器
    Visual Studio安装SVN插件
  • 原文地址:https://www.cnblogs.com/shangyueyue/p/10502010.html
Copyright © 2011-2022 走看看