[英]Nodejs library / module for developing interactive CLI apps?
been googling for this and searching stackoverflow, but am not coming across anything. 一直在为此进行搜索并搜索stackoverflow,但没有遇到任何问题。 I want to develop an interactive shell with node, and wondering on the best approach for this.
我想开发一个带有节点的交互式外壳,并想知道为此的最佳方法。 Is there a library that anyone could recommend to use?
有没有任何人可以推荐使用的库?
I have written a library, and now want a CLI interface to interact with it, by 2 methods: running the app with parameters, or via interactive shell. 我已经编写了一个库,现在希望CLI界面通过两种方法与之交互:使用参数运行应用程序或通过交互式shell。 eg
例如
$ node myapp doSomething
App Result: I did something
$ node myapp cli
Entering interactive mode...
myapp>
myapp> doSomething
App Result: I did something
myapp>
Any suggestions? 有什么建议么?
I guess commander.js is what you are looking for. 我猜想commander.js是您想要的。
https://github.com/visionmedia/commander.js https://github.com/visionmedia/commander.js
http://oscar-mejia.com/blog/how-to-create-a-command-line-program-with-nodejs/ http://oscar-mejia.com/blog/how-to-create-a-command-line-program-with-nodejs/
Also have a look at REPL http://nodejs.org/api/repl.html 也可以看看REPL http://nodejs.org/api/repl.html
Vorpal is a framework exactly for what the question describes, although they call it an ' immersive cli '. 尽管他们称其为“ 沉浸式cli ”,但Vorpal正是该问题描述的框架。
var vorpal = require('vorpal')();
vorpal
.command('doSomething')
.action(function (args, cb){
this.log('App Result: I did something');
cb();
});
vorpal
.delimiter('myapp>')
.show();
I've recently started a project for an enhanced REPL that provides plugins and multi-language support (like CoffeeScript): 我最近启动了一个增强型REPL项目,该项目提供了插件和多语言支持(例如CoffeeScript):
http://danielgtaylor.github.com/nesh/ http://danielgtaylor.github.com/nesh/
It might be useful for you when building interactive apps. 在构建交互式应用程序时,它可能对您有用。 Let me know if you'd like to see any features in Nesh!
让我知道您是否想在Nesh中看到任何功能!
This question is a bit old, but I've given some mileage to a module I built a while ago that will launch an interactive shell-like command prompt: 这个问题有点老了,但是我已经为前不久构建的模块投入了一些精力,该模块将启动交互式的类似于shell的命令提示符:
https://github.com/mrvisser/node-readcommand https://github.com/mrvisser/node-readcommand
The key difference to this over something like commander is it allows you to maintain shell session state and accept the commands internally in Node.js, as opposed to requiring every invocation to be a stateless re-run with the shell's parsed arguments. 与commander之类的东西相比,此方法的主要区别在于,它允许您维护Shell会话状态并在Node.js内部接受命令,而不是要求每次调用都必须使用shell的解析参数进行无状态重新运行。 It effectively wraps node's internal
readline
module to provide: 它有效地包装了节点的内部
readline
模块以提供:
readcommand.loop
) readcommand.loop
) readline
s text-based auto-complete support readline
的基于文本的自动完成支持 Hoping someone else finds it useful, too. 希望其他人也觉得它有用。
For a more advanced and opinionated interactive CLI framework, I also built node-corporal
: https://github.com/mrvisser/node-corporal . 对于更高级和自以为是的交互式CLI框架,我还构建了
node-corporal
: https : //github.com/mrvisser/node-corporal 。 Which is probably more than you're looking for, but it provides a structure and environment for whipping together CLI apps. 这可能比您想要的要多,但它提供了将CLI应用程序整合在一起的结构和环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.