Interactive command line user interfaces in node [closed]

时光总嘲笑我的痴心妄想 提交于 2021-01-29 02:31:46

问题


The Command npm init, ask a series of questions and gets those answer and write it in a file?

How can I create a similar command line utility in node?

Is there any packages available?

Some Examples would be much helpful for me.


回答1:


The inquirier package should meet your needs. Have a look at the examples they provide here on github




回答2:


Vorpal.js is built on top of Inquirer.js, and provides an interactive CLI, with an easy API for adding commands, which seems to be what you are looking for.

Implementing is easy:

var vorpal = require('vorpal')();

vorpal
  .delimiter('myapp$')
  .show();

vorpal
  .command('foo', 'Logs "bar".')
  .action(function(args, cb){
    this.log('bar');
    cb();
  });

Your app is now interactive:

$ node app.js
myapp$ foo
bar
myapp$

Disclaimer: I wrote Vorpal, so if you have questions, ask away.



来源:https://stackoverflow.com/questions/32735809/interactive-command-line-user-interfaces-in-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!