Which Node module provides the CLI prompt?

I searched extensively and widely for a node module that provides a CLPL command-line interface like CLI for a node application.

What I'm looking for is a hybrid between inquirer or prompt and commander .

Node provides a built-in REPL module , however it just exposes the raw javascript of your application. I want to create a virtual interface for an application.

For example, if you run node server.js, you will be prompted:

server:~$

This will behave like a basic unix prompt in your own virtual context. Press enter:

server:~$
server:~$

Or help:

server:~$ help

Commands:

debug [setting]   Enables or disables debugging.
show stats        Displays live stats for your web server.

server:~$

And you can execute custom commands:

server:~$ debug on -v 7
Debugging turned on with a verbosity of 7
... live logging ...

, NPM ?


9

- , , Vorpal, CLI Node.

+4
3

REPL . " " repl, .

, crappily , , :

var repl = require("repl");

var cmds = {
    "help" : function(input, context) { 
        return "debug [setting]   Enables or disables debugging..." 
    },
    "debug" : function(input, context) {
        var args = input.split(/\s+/).slice(1);

        var onoff = args[0];
        var verbosity = args[2];

        return "Debugging turned " + onoff + " with a verbosity of " + verbosity;
    },
    "exit": function(input, context) {
        process.exit();
    },
    "default" : function(input, context) { 
        return "Command not understood";
    }
};

function eval(input, context, filename, callback) {
    var cmd = input.split(/\s+/)[0];
    var result = (cmds[cmd] || cmds["default"])(input, context);
    callback(null, result);
}

repl.start({
    prompt: "server:~$ ",
    eval: eval
});

, , REPL; , , , , , , .

+3

node-shell, . .

:

Shell API Connect, Express inspired .

  • ,
  • (, ctrl-a, ctrl-u,...)
  • , .
  • , , Express routing
  • , middlewares .
  • API , Connect Express
  • Redis, HTTP-, Cloud9, CoffeeScript,...

reddis , .

+1

It looks like you are really looking for a module readlinethat activates a module repl.

0
source

Source: https://habr.com/ru/post/1589059/


All Articles