The CLI (as for "command line interpreter") adds an element to your web application's GUI for text-based user interaction via a set of commands. It is lightweight, fully customizable and the integration of your own commands is a cakewalk.
Table of Contents
No installation required. Just link the source (i.e. from JsDelivr):
<script src="https://cdn.jsdelivr.net/gh/chzager/cli/cli.min.js"></script>
The type definitions are avaliable at https://chzager.github.io/cli/cli.d.ts.
Usage doesn't get any easier: Define your commands and instantiate a CommandLineInterpreter
object.
const myCommands = {
"hello": (cli) => {
cli.writeLn("Hello, world!");
},
};
new CommandLineInterpreter(myCommands);
Let's get more interactive:
const myCommands = {
"hello": (cli) => {
return new Promise((resolve) => {
cli.readLn("What's your name? ").then((name) => {
cli.writeLn(`Hello, ${name}!`);
resolve();
});
});
},
};