Giter VIP home page Giter VIP logo

clinterface's Introduction

Clinterface

A very simple library to create a runtime CLI for your Node.js application.

Usage

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)>)

Commands

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.

Other ways

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 */ }
  }
)

Standard commands

There are a few Standard commands.

Exit:

Exits the application with code 0.

$ exit

Help:

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.

Echo, log, warn, error, success

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!

Options

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
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.