zoukankan      html  css  js  c++  java
  • vorpal 又一个方便的cli 开发包

    vorpal 是一个npm 包,我们可以用来开发专业的cli 程序

    简单使用

    • 初始化项目
    yarn init -y
    • 添加依赖
    yarn add vorpal
    • 简单demo
    app.js
    // const vorpal = require("vorpal")();
    // vorpal.show()
    const vorpal = require('vorpal')();
    vorpal
      .command('say [words...]')
      .option('-b, --backwards')
      .option('-t, --twice')
      .action(function (args, callback) {
        let str = args.words.join(' ');
        str = (args.options.backwards) ?
          str.split('').reverse().join('') :
          str;
        this.log(str);
        callback();
      })
      vorpal
      .command('sayapp [words...]')
      .action(function (args, cb) {
        this.log(args.words.join(' '));
        cb();
      });
    vorpal
      .command('reverse [words...]')
      .action(function (args, cb) {
        this.log(args.stdin.split('').reverse().join(''));
        cb();
      });
    vorpal
      .command('color [color] [text...]')
      .autocomplete(['2018-12-31', '2019-01-03', '2019-03-01'])
      .action(function (args, cb) {
        this.log(args)
        this.log(vorpal.chalk[args.color](args.text.join('')));
        cb();
      });
      vorpal
      .command('order pizza')
      .option('--anchovies')
      .action(function (args, cb) {
        const self = this;
        this.prompt({
          type: 'input',
          name: 'time',
          message: 'When would you like your pizza?'
        }, function (result) {
          self.log(`Okay, ${result.time} it is!`);
          cb();
        });
      });
      vorpal.delimiter('dalongrong$').
      show()
     
     
    • 运行效果

    node app.js
    node app.js
    dalongrong$
    dalongrong$ ls
      Invalid Command. Showing Help:
      Commands:
        help [command...] Provides help for a given command.
        exit Exits application.
        say [options] [words...]
        sayapp [words...]
        reverse [words...]
        color [color] [text...]
        order pizza [options]
    dalongrong$
     

    参考资料

    https://github.com/dthree/vorpal
    https://developer.telerik.com/featured/creating-node-js-command-line-utilities-improve-workflow/
    https://github.com/rongfengliang/vorpal-pkg-demo

  • 相关阅读:
    poj3436(ACM Computer Factory)
    一位ACMer过来人的心得
    poj1459(Power Network)
    (转)网络流—最大流(Edmond-Karp算法)
    poj1611(The Suspects)
    构建之法阅读笔记01
    第三周总结
    全国疫情可视化地图
    第二周总结
    作业--数组(大数)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10211453.html
Copyright © 2011-2022 走看看