A very simple library to create a runtime CLI for your Node.js application.
To use Clinterface, simply install it using NPM and require the instance.
npm install clinterface --save
var clinterface = require('clinterface')
Then, initialize it using the following two arguments:
var cli = new clinterface(<Commands>, <Options (optional)>)
The commands parameter has to look like this:
{
commandName: {}, // Command object
test: {} // Command object
}
Each command object has a description, a usage and a method field.
// Command object
{
description: 'Simple description of command',
usage: 'commandName <name> <password>',
method: function (args) {
// Do your call handling here
}
}
Now you can use the commands in your running node.js application.
You can also add commands using the .command() function. This can be done at any point during runtime.
cli.command(<name>, <command>)
cli.command(
'test',
{
description: 'Simple test command',
usage: 'test',
method: function (args) { /* Test method */ }
}
)
There are a few Standard commands.
Exits the application with code 0.
$ exit
Lists all the available commands.
$ help
⌨️ Available commands:
help Shows all available commands.
exit Exits the process with code 0.
$ help exit
exit
Exits the process with code 0.
Helper functions to display text in the console. Each with respective coloring and formatting.
$ echo This is a test!
This is a test!
$ success This is good!
[Clinterface 🎉 ] This is good!
You can pass the option parameter. You can modify these parameters:
{
available: '⌨️ Available commands:',
bye: '🖖 Bye bye!',
prefix: '🤖 > ',
errorPrefix: '[Clinterface ⚡️ ]',
successPrefix: '[Clinterface 🎉 ]',
warningPrefix: '[Clinterface 🕵 ]',
logPrefix: '[Clinterface 📝 ]',
hideRegisterLogs: true
}