• 一、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);
  • 相关阅读:
    LeetCode c++-- 118.杨辉三角
    LeetCode c++ --896. 单调数列
    LeetCode c++--1551. 使数组中所有元素相等的最小操作数
    LeetCode c++:1550. 存在连续三个奇数的数组
    LeetCode c++--字符串转换整数 (atoi)
    c++ 顺序容器常用知识总结
    c++基础知识之容器一:顺序容器
    小菜鸡c++ LeetCode初级算法之一——数组(删除排序数组中的重复项)
    JVM
    BATCH、事务、CLOB、BLOB
  • 原文地址:https://www.cnblogs.com/shangyueyue/p/10502010.html
Copyright © 2020-2023  润新知