Reputation: 4017
I'm developing command line interface with node.js. Can we have custom console like mysql? Like, if we type mysql and enter in console it will come as mysql>
so we can do all mysql related operation until we exit. Like that in node.js
> node hello
hello> help
hello> list apps
.
.
hello> exit
>
>node world
world>operation related to world
.
.
world>exit
>
// or if it is executable
>hello
hello>help
hello>list app
hello>exit
>
It would be great if you give some suggestion.
Upvotes: 2
Views: 80
Reputation: 20730
Yes. Check out Vorpal.js. It was made for this exact purpose.
var vorpal = require('vorpal')();
... // your app code
vorpal.command('list apps')
.action(function (args, cb){
var self = this;
myapps.forEach(function(app) {
self.log(app.name);
});
cb();
});
vorpal
.delimiter('hello>')
.show();
And then you'll have this:
$ node hello.js
hello> list apps
..
..
hello>
Disclaimer: I wrote Vorpal.
Upvotes: 2